Plot function in Non-linear optimization

2 次查看(过去 30 天)
%% Introduction to Constrained non-linear minimization
%Objective
fcn=@(x,y) log(1+3*(y-(x.^3-x)).^2+(x-4/3).^2);
%% plot
fsurf(fcn,[-2.5 2.5],'ShowContours','on')
view(127,38)
%% Create optimization
prob=optimproblem;
%% define variables
x=optimvar('x','LowerBound',-2.5,'UpperBound',2.5);
y=optimvar('y','LowerBound',-2.5,'UpperBound',2.5);
%% Define objective
prob.Objective = log(1+3*(y-(x.^3-x)).^2+(x-4/3).^2);
%% set optimization options
initialpt.x=-1;
initialpt.y=2;
options=optimoptions(prob,'Display','iter','OutputFcn',@plotUpdate);
%% solve the problem
[sol,fval,exitflag,output] = solve(prob,initialpt,'Options',options);
I am unable to get the @plotUpdate command working and thus, I do not get the contour plot with optimal x path. Could someone help me?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Nonlinear Optimization 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by