graph mesh code help

1 次查看(过去 30 天)
Chester710
Chester710 2022-10-20
评论: Chester710 2022-10-20
hey i'm trying to graph this code but i get error "Z must be a matrix, not a scalar or vector."
syms x
a=1-(exp(-x/sqrt(2))/2+exp(-x/sqrt(2)));
b=exp(-x/sqrt(2))/((2+exp(-x/sqrt(2)))^2);
c=((exp(-x/sqrt(2))*(exp(-x/sqrt(2))-2)))/4*((2+exp(-x/sqrt(2)))^3);
d=(exp(-x/sqrt(2))*(((exp(-x/sqrt(2)))^2)-8*(exp(-x/sqrt(2)))+4))/24*((2+exp(-x/sqrt(2)))^4);
syms t
[X,Y]=meshgrid(-1:1.-1:1)
Z=a+(t*b)+(c*t^2)+(d*t^3)
mesh(X,Y,Z)
  2 个评论
Dyuman Joshi
Dyuman Joshi 2022-10-20
The increment value seems to be incorrect or a typo
[X,Y]=meshgrid(-1:1.-1:1)
Also, for using mesh(), it is necessary for the 3rd input or Z, to be a matrix.
Chester710
Chester710 2022-10-20
Thanks for answering
then how can i write this ?

请先登录,再进行评论。

采纳的回答

David Hill
David Hill 2022-10-20
a=@(x)1-exp(-x/sqrt(2))./(2+exp(-x/sqrt(2)));
b=@(x)exp(-x/sqrt(2))./((2+exp(-x/sqrt(2))).^2);
c=@(x)((exp(-x/sqrt(2)).*(exp(-x/sqrt(2))-2)))./(4*((2+exp(-x/sqrt(2))).^3));
d=@(x)(exp(-x/sqrt(2)).*(((exp(-x/sqrt(2))).^2)-8*(exp(-x/sqrt(2)))+4))./(24*((2+exp(-x/sqrt(2))).^4));
Z=@(x,t)a(x)+t.*b(x)+c(x).*t.^2+d(x).*t.^3;
[x,t]=meshgrid(-1:.01:1);
mesh(x,t,Z(x,t));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by