带约束的MATLAB中的轮廓图 [英] Contour plot in MATLAB with constraints

查看:92
本文介绍了带约束的MATLAB中的轮廓图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MATLAB的新手,遇到了一些问题.

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

我需要绘制以下非线性优化问题的轮廓图:

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

以确定该功能的可行区域.我曾尝试在 Mathworks 上进行搜索,但到目前为止还没有任何运气.我也有以下示例:

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):

推荐答案

您的代码有效,您只需要设置限制

Your code works, you just need to set the limits

% your code here

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

这篇关于带约束的MATLAB中的轮廓图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆