Finite Differencing Transient Conduction

7 views (last 30 days)
Hello,
I'm attempting to conduct a finite difference approach to a transient conduction problem.
  • Rows are time steps
  • Columns are Length
My initial condition is:
  • At time = 0, Temp Is uniform at 573K (except for at L=0 where it's 673K).
My Boundary Condition is:
  • Temp = 673K at L = 0, constant
  • at L = L, no heat transfer, insulated
My descritization loop appears below.
I can populate T0 with the intial and boundary conditions above, but am running into a problem in the finitie difference for loop.
Any help is appreciated.
clc
clear all
close all
ri = 0.0125;
ro = 0.0375;
R = ro-ri;
t=2000;
k = 50; %W/mK
cp = 1750; %W s /kg K
rho = 1500; %kg/m3
alpha = k /(rho*cp); % m2/s
dr = 50;
dt = 1;
FO = alpha* dt/(dr^2);
T0 = zeros(t+1,51);
T1 = zeros(t+1,51);
for i = 1:t
T0(i,1) = 673;
T0 = T1;
end
for j = 2:t
for i = 1
T0(i,j) = 573;
T0 = T1;
end
end
for j = 3:t
for i = 2:t
T0(i,j) = (dr/R)*FO*T1(i+1,j)-(dr/R)*FO*T1(i,j)+FO*T1(i-1,j)-2*FO*T1(i,j)+FO*T1(i+1,j);
end
T0 = T1;
end
  1 Comment
Torsten
Torsten on 7 May 2023
Moved: VBBV on 7 May 2023
Why do both loops run over t ?
And why do you divide by R = ro-ri and not be r ?
Two of many other errors in your code.
Seems you better stick to the "pdepe" solution.

Sign in to comment.

Accepted Answer

VBBV
VBBV on 7 May 2023
Edited: VBBV on 7 May 2023
May be the central and forward difference schemes are not correct, but the following change will avoid the code errors
clc
clear all
close all
ri = 0.0125;
ro = 0.0375;
R = ro-ri;
t=2000;
k = 50; %W/mK
cp = 1750; %W s /kg K
rho = 1500; %kg/m3
alpha = k /(rho*cp); % m2/s
dr = 50;
dt = 1;
FO = alpha* dt/(dr^2);
T0 = zeros(t+1,51);
T1 = zeros(t+1,51);
for i = 1:t+1
T0(i,1) = 673;
end
for j = 1:t+1
T0(1,j) = 573;
end
T1 = T0;
for j = 2:t
for i = 2:t
% T0(i,j) = FO*((dr/R)*(T1(i+1,j)-T1(i,j))+T1(i-1,j)-(2*T1(i,j)+T1(i+1,j)));
T0(i,j) = T1(i,j)+ (dr/R)*FO*T1(i+1,j)-(dr/R)*FO*T1(i,j)+(FO*T1(i-1,j)-2*FO*T1(i,j)+FO*T1(i+1,j));
end
T1 = T0;
end
T0, T1

More Answers (1)

Walter Roberson
Walter Roberson on 7 May 2023
T0 = zeros(t+1,51);
T1 = zeros(t+1,51);
Okay, both zeros
for i = 1:t
T0(i,1) = 673;
You replace a particular element of T0 with 673. On the first iteration, T0 will now have 673 in row 1 column 1, and zeros everywhere else.
T0 = T1;
And there you overwrite all of T0 with the zeros stored in T1. If that were your intent then you could be more efficient by just skipping the loop entirely since you already st T0 to all 0.

Categories

Find more on Heat and Mass Transfer 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!