Contour plot in MATLAB with constraints

一笑奈何 提交于 2019-12-10 22:48:06

问题


I'm completely new to MATLAB and have some problems.

I need to make a contour plot of the following nonlinear optimization problem:

In order to determine the feasible region for the function. I've tried searching on Mathworks, but haven't had any luck so far. I also have the following example:

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

But this is not shown the way it should either (it is suppose to look like this):


回答1:


Your code works, you just need to set the limits

% your code here

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




回答2:


You're already there. Only limits of y-axis need adjustment. Add the following line:

ylim([-5 5])


来源:https://stackoverflow.com/questions/42141543/contour-plot-in-matlab-with-constraints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!