如何为优化执行图形解决方案?

时间:2017-02-24 14:10:48

标签: matlab optimization plot

我有一个非常简单的问题,可以使用Matlabfmincon上轻松解决。但是如果不使用fmincon,我该如何以图形方式解决它? 我试图绘制优化函数和约束函数。但我不知道如何解释它!请检查我的代码天气我在正确的道路上。

syms myNorm(x,y) const(x,y)

funny(x,y)= sqrt(x^2+y^2);
con = (x/2)^0.75 + (y/3)^0.75 - 1;
fsurf(funny, [0 2 0 3],'FaceColor','b', 'FaceAlpha', 0.5)
hold on
fsurf(con, [0 2 0 3],'FaceColor','y', 'FaceAlpha', 0.5)

使用fmincon解决方案是1.0557, 0.8278

1 个答案:

答案 0 :(得分:2)

免责声明:我没有MATLAB 2016a,所以我无法象征性地做到这一点。相反,我可以用数字来做。

[x,y]=meshgrid(0:0.01:2,0:0.01:3);

funny= sqrt(x.^2+y.^2);
con = (abs((x/2).^0.75 + (y/3).^0.75 - 1)<0.01); % numerically will never be ==0
funnycon=funny;
funnycon(~con)=NaN; %if it doesn't match condition, delete

hold on
surf(x,y,funnycon,'linestyle','none','FaceColor','r')
surf(x,y,funny, 'FaceAlpha', 0.5,'linestyle','none')
axis tight;
view(3)

% find the point numerically. We only have 0.01 maximum accuracy (beause
% meshgrid)
funnycon=funny;
funnycon(~con)=Inf;
[~,I]=min(funnycon(:));

minX=x(I);
minY=y(I);

% plot minimum
plot3(minX,minY,funnycon(I),'bo','markersize',5,'markerfacecolor','b')

enter image description here