changing timestamp t and plotting the results.
1 次查看(过去 30 天)
显示 更早的评论
I managed to code when t=0, but i still need to code for when t=1000 and when t=2000, as wellas plotting each of the graphs.
In which part of the code do i add so that i change t?
n=5;
dt=1000;
k=15;
rho=8055;
Cp=480;
deltax=1.6;
x=linspace(-0.8,0.8,n);
T=zeros(1,5); T(1,1)=40; T(1,5)=40;
figure
plot(x,T)
title('Temperature distribution at t=0')
xlabel('x')
ylabel('Temperature')
hold on;
2 个评论
Torsten
2022-6-28
Proceed as described in your assignment:
n = 5;
dt = 1000;
L = 0.8;
k = 15;
rho = 8055;
Cp = 480;
x = linspace(-L,L,n);
deltax = x(2)-x(1);
T=zeros(1,5); T(1,1)=40; T(1,5)=40;
plot(x,T)
hold on
T_old = T;
T(2:end-1) = T_old(2:end-1) + k/(rho*Cp) * dt * (T_old(3:end)-2*T_old(2:end-1)+T_old(1:end-2))/(2*deltax);
plot(x,T)
T_old = T;
T(2:end-1) = T_old(2:end-1) + k/(rho*Cp) * dt * (T_old(3:end)-2*T_old(2:end-1)+T_old(1:end-2))/(2*deltax);
plot(x,T)
回答(1 个)
Dyuman Joshi
2022-6-29
%building on Torsten's code
n=5;
dt=1000;
k=15;
rho=8055;
Cp=480;
x=linspace(-0.8,0.8,n);
deltax = x(2)-x(1);
T=zeros(1,5); T(1,1)=40; T(1,5)=40;
figure
plot(x,T)
xlabel('x')
ylabel('Temperature')
hold on;
for i=0:dt:35000
T_old = T;
T(2:end-1) = T_old(2:end-1) + k*dt/(rho*Cp)*(T_old(3:end)-2*T_old(2:end-1)+T_old(1:end-2))/(deltax.^2);
plot(x,T)
pause(0.1) %pausing 0.1 seconds between each plot
end
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!