I'm plotting a solution to a PDE using surf but the graph turns out wrong?
Show older comments
I'm trying to plot the solution to a PDE, which is an infinite series:
So far this is my code, I can't see what's wrong with it. I've attached the graph i got below.
edit: the sin part is part of the summation, and the original pde is:


xRange = 0:0.1:6;
tRange = 0:0.1:6;
[x,t] = meshgrid(xRange,tRange);
u = zeros(size(x));
for n=1:300
u = u+(4/(n^3*pi^3)+(4/(n*pi)-4/(n^3*pi^3))*exp(-n^2*pi^2.*t)).*sin(n*pi/2*x);
end
surf(x,t,u);
xlabel("X");
ylabel("T");
zlabel("U");
Accepted Answer
More Answers (2)
Max Heiken
on 10 Jun 2021
Edited: Max Heiken
on 10 Jun 2021
The part with the sin is missing in your code.
for n=1:10
u = u+(4/(n^3*pi^3)+(4/(n*pi)-4/(n^3*pi^3))*exp(-n^2*pi^2*t)).*sin(n*pi*x/2);
end
surf(x,t,u);
edited: It seems like the sin part is supposed to be part of the summation.
1 Comment
Vicky Ngo
on 10 Jun 2021
Categories
Find more on Electromagnetics 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!