Z must be a matrix, not a scalar or vector.

2 次查看(过去 30 天)
I could't find the Problem. Need a help!!!
%variable declare
syms x;
syms t;
%putting the value
a=1;
b=-2;
c=-1;
alpha=1;
p=0;
%mesh plot
x = -3:.1:3;
y = -3:.1:3;
[X,Y] = meshgrid(x,t);
%vartheta equation
vartheta = ((a/alpha)*X.^alpha)+((b/alpha)*p^alpha)+c*t;
%delta equation
delta=-(2*c)/(b*a^2);
%main function
Z=-(2*(c^2)*((tanh(sqrt(-delta).*vartheta)).^2))/(b*delta*a^3);
mesh(X,Y,Z)
grid on
hold on
Result:
Error using mesh (line 71)
Z must be a matrix, not a scalar or vector.
Error in M3_1_29_3 (line 30)
mesh(X,Y,Z)
  2 个评论
Torsten
Torsten 2022-6-12
编辑:Torsten 2022-6-12
Why do you define
y = -3:.1:3
and don't use "y" anywhere in your code ?
And in order to plot, t must be given a value - i can't remain a symbolic variable.
Why do you use symbolic variables at all ?
Jeffrey Clark
Jeffrey Clark 2022-6-12
Asuming you meant to use y or Y where t is used, vartheta should be computed as a matrix since X is used, and therefore Z would be a matrix. Since the error indicates that Z is not a matrix the code you shared must have other copy and paste issues. Please retest after removing the syms lines which may be causing some of the issue. Then upload that code if it still gives the error or something else.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2022-6-12
%putting the value
a=1;
b=-2;
c=-1;
alpha=1;
p=0;
%mesh plot
x = -3:.1:3;
y = -3:.1:3;
[X,Y] = meshgrid(x,y);
%vartheta equation
vartheta = ((a/alpha)*X.^alpha)+((b/alpha)*p^alpha)+c*Y;
%delta equation
delta=-(2*c)/(b*a^2);
%main function
Z=-(2*(c^2)*((tanh(sqrt(-delta).*vartheta)).^2))/(b*delta*a^3);
mesh(X,Y,Z)
grid on
hold on

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by