graph mesh code help
1 view (last 30 days)
Show older comments
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 Comments
Dyuman Joshi
on 20 Oct 2022
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.
Accepted Answer
David Hill
on 20 Oct 2022
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));
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!