surf,mesh
函数fmincon
是MATLAB中用于求解非线性规划问题的函数。它的基本语法如下:
surf(X, Y, Z, CO, Name,value)
surf, mesh
:绘制曲面图X, Y, Z
:表示初始解的猜测CO
:曲面的颜色Name
:曲面的属性Value
:曲面属性的值针对函数
z
=
sin
(
x
2
+
y
2
)
/
(
x
2
+
y
2
)
z = \sin(\sqrt{x^2+y^2})/(\sqrt{x^2+y^2})
z=sin(x2+y2)/(x2+y2)
绘制
clc
figure('Color','w')
%RGB自定义颜色
subplot(1,2,1)
[X,Y] = meshgrid(-8:.3:8);
R=sqrt(X.*X+Y.*Y);
Z=sin(R)./R;
CO(:,:,1) = 0.8*ones(size(X,1)); % red
CO(:,:,2) = ones(size(X,1)).*linspace(0.5,0.6,size(X,1)); % green
CO(:,:,3) = ones(size(X,1)).*linspace(0,1,size(X,1)); % blue
surf(X,Y,Z,CO,'EdgeColor','b','EdgeAlpha',0.2)
set(gca,'xtick',[],'ytick',[],'ztick',[],'xcolor','w','ycolor','w','zcolor','w')
%系统颜色
subplot(1,2,2)
[X,Y] = meshgrid(-8:.3:8);
R=sqrt(X.*X+Y.*Y);
Z=sin(R)./R;
surf(X,Y,Z,'EdgeColor','b','EdgeAlpha',0.2)
set(gca,'xtick',[],'ytick',[],'ztick',[],'xcolor','w','ycolor','w','zcolor','w')
colormap summer%系统颜色
仿真结果
不规则meshgrid,非矩形meshgrid,如