作图表示函数z=x*exp(-x2-y2) (-1<x<1,0<y<2)沿x轴方向梯度
clear
a=-1:0.1:1;
b=0:0.1:2;
[x,y]=meshgrid(a,b);
z=x.*exp(-x.2-y.2);
[px,py]=gradient(z,0.1,0.1);
contour(a,b,z),hold on,
quiver(a,b,px,py),hold off
作图表示函数z=x*exp(-x2-y2) (-1<x<1,0<y<2)沿x轴方向梯度
clear
a=-1:0.1:1;
b=0:0.1:2;
[x,y]=meshgrid(a,b);
z=x.*exp(-x.2-y.2);
[px,py]=gradient(z,0.1,0.1);
contour(a,b,z),hold on,
quiver(a,b,px,py),hold off