2017-02-09 88 views
3

我對MATLAB完全陌生並且有一些問題。帶有約束條件的MATLAB中的輪廓圖

我需要做下面的非線性優化問題的等高線圖:

enter image description here

爲了確定該函數的可行域。我試過在Mathworks上搜索,但到目前爲止還沒有任何運氣。我也有下面的例子:

x = -5:0.005:5; 
y = -5:0.005:5; 
[X,Y] = meshgrid(x,y); 
F = (X.^2+Y-11).^2 + (X + Y.^2 - 7).^2; 
v = [0:2:10 10:10:100 100:20:200] 
[c,h]=contour(X,Y,F,v,'linewidth',2); 

colorbar 
yc1 = (x+2).^2; 
yc2 = (4*x)/10; 

hold on 
fill(x,yc1,[0.7 0.7 0.7],'facealpha',0.2) 
fill([x x(end) x(1)],[yc2 -5 -5],[0.7 0.7 0.7],'facealpha',0.2) 
hold off 

但是,這並不表明,它應該是(這是假設是這樣的)方式:

enter image description here

回答

1

你已經在那裏。只有y軸的限制需要調整。添加以下行:

ylim([-5 5]) 
2

你的代碼的工作,你只需要設置的限制

% your code here 

% Set limits 
ylim([-5,5]) 
% Set colours 
colormap 'jet' 

contour plot