2017-02-24 40 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