How to implement mesh diagram?
Show older comments
How to do the mesh diagram in this coding with the corresponding of T,L and time?
Below here are my codes:
clc;
clear all;
L=20;
alpha=0.23;
t_final=60;
n=20;
T0=20;
T1s=100;
T2s=0;
dx=L/n;
dt=2;
x=dx/2:dx:L-dx/2;
T=ones(n,1)*T0;
dTdt=zeros(n,1);
t=0:dt:t_final;
for j=1:length(t)
for i=2:n-1
dTdt(i)=alpha*(T(i+1)+T(i-1)-2*T(i))/dx^2;
end
dTdt(1)=alpha*(T(2)+T1s-2*T(1))/dx^2;
dTdt(n)=alpha*(T2s+T(n-1)-2*T(n))/dx^2;
T=T+dTdt*dt;
end
disp(T)
figure(1)
plot(x,T,'Linewidth',3)
axis([0 L 0 50])
xlabel('Distance(m)')
ylabel('Temperature(\circC)')
Answers (1)
L=20;
alpha=0.23;
t_final=60;
n=20;
T0=20;
T1s=100;
T2s=0;
dx=L/n;
dt=2;
x=dx/2:dx:L-dx/2;
t = 0:dt:t_final;
nt = length(t);
T = zeros(n, nt);
T(:,1) = T0;
for j=1:nt-1
dTdt=zeros(n,1);
for i=2:n-1
dTdt(i) = alpha*(T(i+1,j)+T(i-1,j)-2*T(i,j))/dx^2;
end
dTdt(1) = alpha*(T(2,j)+T1s-2*T(1,j))/dx^2;
dTdt(n) = alpha*(T2s+T(n-1,j)-2*T(n,j))/dx^2;
T(:,j+1) = T(:,j) + dTdt*dt;
end
disp(T)
figure(1)
mesh(x,t,T.')
xlabel('Distance(m)')
ylabel('Temperature(\circC)')
zlabel('T, whatever that is')
1 Comment
Deck Zhan Sim
on 20 Jan 2021
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!