Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
shahariar Ryehan
shahariar Ryehan el 12 de Jun. de 2022
Respondida: Walter Roberson el 12 de Jun. de 2022
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 comentarios
Torsten
Torsten el 12 de Jun. de 2022
Editada: Torsten el 12 de Jun. de 2022
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 el 12 de Jun. de 2022
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.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 12 de Jun. de 2022
%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

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by