Plotting a temperature graphs of a heat equation of a rod
2 views (last 30 days)
Show older comments
The values of c, L and deltat are choosen by myself. The equation is attached in the picture and this my code. I can't seem to get the curve correctly for the temperature of the rod. Is there anything wrong with my code?
syms n;
c = 4;
L = 6;
deltat = 0.2;
x = [0:6];
for k = 1:5
t = (deltat*k);
u = (200/pi)*symsum((((-1)^(n+1))/n)*(sin((n*x*pi)/L))*(exp(-(((c*n*pi)/L)^2)*t)),n,1,1000);
plot(x,u)
hold on
end
0 Comments
Accepted Answer
Star Strider
on 9 Feb 2018
The Symbolic Math Toolbox isn’t the best option for this. It’s possible to vectorise the sin*exp term, and is only necessary to sum over ‘n’ in a loop:
c = 4;
L = 6;
deltat = 0.2;
k = 0:4;
t = k*deltat;
x = linspace(0,6,50);
xp = c*pi/L^2;
[T,X] = meshgrid(t,x);
u = zeros(size(T));
for n = 1:1000
u = u + ((-1)^(n+1)/n) * (sin(n*pi*X/L).*exp(-n*xp*T));
end
figure(1)
surf(T, X, u)
grid on
xlabel('\itt\rm')
ylabel('\itx\rm')
zlabel('\itu(x,t)\rm')
view(125, 35)
Experiment to get the result you want.
5 Comments
Star Strider
on 10 Feb 2018
As always, my pleasure.
If my Answer helped you solve your problem, please Accept it!
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!