changing timestamp t and plotting the results.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Torsten
am 28 Jun. 2022
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)
Antworten (1)
Dyuman Joshi
am 29 Jun. 2022
%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 Kommentare
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!