x=linspace(-5,5);y=linspace(-3,3);
[X,Y]=meshgrid(x,y);
Z=(1+X.^2+Y.^2+X+X.*Y).^(-1);
subplot(1,2,1);
cs=contour(X,Y,Z);clabel(cs);
xlabel('x');ylabel('y');title('(a)contour plot');grid;
subplot(1,2,2);
cs=surfc(X,Y,Z);
zmin=floor(min(Z));
zmax=ceil(max(Z));
xlabel('x');ylabel('y');zlabel('h(x,y)');title('(b)mesh plot')
%consulting the plots, the value of h(x,y) is always positive, so finding
%the maximum place of h(x,y) is equivalent to finding the minimum place of g(x,y)=1+x.^2+y.^2+x+x.*y
g=@(x) 1+x(1).^2+x(2).^2+x(1)+x(1).*x(2);
P=fminsearch(@(x) g(x),[-5,5]);
X=P(1)
Y=P(2)
hmaximum=(1+X.^2+Y.^2+X+X.*Y).^(-1)
%At point(-0.6667, 0.3333), h(x,y) has the maximum value: 1.5
matlab编程.zip_matlab数值优化
版权申诉
48 浏览量
2022-09-23
18:41:29
上传
评论
收藏 276KB ZIP 举报
小波思基
- 粉丝: 74
- 资源: 1万+