matlab中的绘图功能问题

时间:2013-06-10 13:32:00

标签: plot matlab-figure

我想在matlab中绘制这个函数: f(x,y)=(x 2 + y 2)^ 0.25 * [sin 2(50(x 2 + y 2)^ 0.1)+ 1.0]; 以下是我写的:

>> x = -100 : 1 : 100; //where x varies
>> y = -100 : 1 : 100; //where y varies
>> A = (power(x, 2)+ power(y, 2));
>> B = 50 * A;
>> C = sin(power(B,0.1));
>> z = (power(A,0.25))*((power(C,2)+1)); 
??? Error using ==> mtimes
Inner matrix dimensions must agree.// how can i resolve this error??

帮助!

1 个答案:

答案 0 :(得分:0)

当你想要逐个元素乘法(*)时,你会得到那个错误,因为你正在使用矩阵乘法(.*)。即使更改了,您的代码仍然不完整,因为xy是向量。您可能想要计算值数组的函数。这可以使用meshgrid完成。有更多信息here

x = -100 : 1 : 100;
y = -100 : 1 : 100;
[X,Y] = meshgrid(x,y);
A = (power(X, 2)+ power(Y, 2));
B = 50 * A;
C = sin(power(B,0.1));
z = (power(A,0.25)).*((power(C,2)+1));
surf(z)
xlabel('x')
ylabel('y')
zlabel('z')

通过一些旋转,图形将如下所示:

enter image description here