Professional Documents
Culture Documents
1. Problem definition
A rod of length 1m is insulated at right end and has 0oC throughout the length. It is heated at
left end resulting in 1oC temperature rise on that end. Find the temperature distribution in rod
at t=0, 0.5, 1, 5, 10 sec.
𝜕𝑇 𝜕2 𝑇
1D heat conduction equation = 𝛼 𝜕𝑥 2
𝜕𝑡
4.2.Discretization
Finite difference discretization method with Forward in Time and Central in Space
scheme.
𝑇𝑖𝑛+1 − 𝑇𝑖𝑛 𝑛
𝑇𝑖+1 − 𝑇𝑖𝑛 + 𝑇𝑖−1
𝑛
=𝛼
∆𝑡 (∆𝑥)2
𝑇𝑖𝑛+1 = 𝛾𝑇𝑖+1
𝑛
+ (1 − 2𝛾)𝑇𝑖𝑛 + 𝛾𝑇𝑖−1
𝑛
∆𝑡
Where 𝛾 = 𝛼 (∆𝑥)2
4.3.Flow chart or pseudo code
Initial conditions
Solve system of
equations
T[i] = T1[i]
Print results
5. Results
Fig.1. solution of 1D heat equation at (a)dt = 0.1 sec, (b) dt = 0.01 sec, which is numerically
unstable
Fig.2. solution of 1D heat equation at dt = 0.001 sec, which is stable (a) Temperature
distribution at (a) t=0, 0.5, 1 sec, (b) t = 5, 10 sec
6. Appendix (code)
Oe18d019_oe19s019.m
clear variables
close all
N = 11;
Lx = 1;
dx = Lx/(N-1);
x = 0:dx:Lx;
alpha=1;
tf = 10;
dt = 0.001;
t = 0:dt:tf;
M = round(tf/dt);
gamma = alpha*dt/dx^2; % To insure stability gamma = dt/dx^2 < = 1/2
u = zeros(N,M);
u(:,1) = 0; % initial cond. f(x)
u(1,:) = 1; % boundary conditions
u(N,:) = 0; % boundary conditions
for j= 1:M-1 % Time Loop
for i= 2:N-1 % Space Loop
u(i,j+1) = gamma*(u(i-1,j))+(1-2*gamma)*u(i,j) + gamma*u(i+1,j);
end
end
figure(1)
plot(x,u(1:end,1),'-',x,u(1:end,500),'-',x,u(1:end,1000),'-',
'linewidth',2)
a = ylabel('Temperature');
set(a,'Fontsize',14);
a = xlabel('x');
set(a,'Fontsize',14);
a=title(['Using The Explicit Method - dt =' num2str(dt)]);
legend('Explicit soln')
legend('t=0s','t=0.5s','t=1.0s')
set(a,'Fontsize',16);
xlim([0 1]);
figure(3)
plot(x,u(1:end,5000),'-',x,u(1:end,10000),'-', 'linewidth',2)
a = ylabel('Temperature');
set(a,'Fontsize',14);
a = xlabel('x');
set(a,'Fontsize',14);
a=title(['Using The Explicit Method - dt =' num2str(dt)]);
legend('t=5s','t=10s')
plot(x,u(1:end,10000),'-', 'linewidth',2)
legend('t=10.0s')