我想画这样的图:
3*x*y
有一个约束
x^2+y^2=8
在Matlab中,所以它应该看起来像这样:
http://www.wolframalpha.com/input/?i=maximize+3xy+on+x%C2%B2%2By%C2%B2%3D8
有什么想法吗?
我试过
ezsurf(@(x,y)3*x.*y)
hold
fimplicit(@(x,y)x.^2+y.^2-8)但是结果很糟糕,线条图没有跟随表面
发布于 2018-01-20 23:00:36
我做到了!
a=@(x,y)3*x.*y
b=@(x,y)x.^2+y.^2-8
constpl(a,b)constpl是我自己定义的函数
function constpl(fun,constraint)
a=fimplicit(constraint);
x=a.XData;
y=a.YData;
z=fun(x,y);
ind=z>=max(z)-0.000001;
x1=x(ind);
y1=y(ind);
z1=z(ind);
ezmesh(fun);
hold on
plot3(x,y,z,'r','LineWidth',2)
scatter3(x1,y1,z1,'rd','LineWidth',3)
hold off
endhttps://stackoverflow.com/questions/48329097
复制相似问题