2017-02-24 78 views
2

我有一个非常简单的问题,可以使用fminconMatlab上轻松解决。但是,如果不使用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

+0

我假设约束是一个逻辑? (x/2)^ 0.75 +(y/3)^ 0.75 - 1> 0'? –

+0

这是一个等式约束'(x/2)^ 0.75 +(y/3)^ 0.75 - 1 = 0' @AnderBiguri –

回答

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