我想在MATLAB中绘制以下函数的梯度。
g(x,y) = [(x^2)-1; -y]
我的代码是:
x = linspace(-3,3);
y = linspace(-3,3);
[xx, yy] = meshgrid(x,y);
z = [xx.^2-1;-yy];
[dx,dy] = gradient(z,.3,.3);
contour(x,y,z)
hold on
quiver(x,y,dx,dy)
但我只是收到这个错误:
The size of Y must match the size of Z or the number of rows
of Z.
我不知道如何才能使两者的大小匹配。y
是一个 1x100 矩阵和z
一个 200x100。为了匹配它们,我需要y
成为 1x200 或z
100x100,但我可以绘制它吗?