Numerical Solution To PDEs
Numerical Solution To PDEs
Question No. 1
Solve the 1-D heat equation that can represented by the governing equation
I: Explicit FTCS
II: Crank Nicolson Implicit Scheme
u (y,0) = 0
u (0,t) = 0
u (10,t) = 100
υ = 10
Δt = 0.02
Δy = 1
0<= y <=10
2. FTCS EXPLICIT SOLUTION TO 1-D HEAT EQUATION
Using forward difference approximation for the time derivative and central difference
approximation for the space derivative, the given PDE becomes;
Δy2
So the FTCS is stable in this case and the solution is presented in the figure below. Code is given
in the appendix for this case.
Code
% SOLUTION OF PDE USING FORWARD TIME CENTRAL SPACE EXPLICIT METHOD
clear
clc
close all
Input Data
nu=10; %thermal diffusivity
h=10; %Length of the plate (m)
dy=1; %Grid step size (m)
y=0:dy:h; %y vector
dt=0.02; %Time step size (s)
d=(nu*dt)/(dy)^2; %Diffusion number to check the stability of the solution
n=101; %No. of time steps
t=(n-1)*dt; %Time upto which solution is to be obtained (s)
m=1+h/dy; %No. of spacial nodes in y direction
U=zeros(m,n); %Generating matrix of m*n size
Initial Condition
U(:,1)=0; %At time=0, Temp is zero
Boundary Conditions
U(1,:)=0;
U(end,:)=100;
for k=1:10:n
figure (1)
% contour (X,Y,U(:,k),'ShowText', 'on')
plot (y,U(1:end,k));
title('Temperature Distribution');
xlabel('y');
ylabel('T');
hold on
text(9,10,'t=0')
text(7,20,'t=0.02')
text(6.5,25,'t=0.04')
text(6,30,'t=0.06')
text(5.8,35,'t=0.08')
text(5,45,'t=0.2')
end
3. THE CRANK NICOLSON’S SOLUTION TO 1-D HEAT EQUATION
Using the beta formulation and the value of beta to be 0.5 where it is equal to the Crank
Nicolson scheme, we have
Δy2 Δy2
After putting the value of beta and rearranging, we have
𝒅 𝒅 𝒅 𝒅
(𝒅 − 𝟏)𝒖𝒏𝒊 − ( ) 𝒖𝒏𝒊−𝟏 − ( ) 𝒖𝒏𝒊+𝟏 = ( ) 𝒖𝒏+𝟏 𝒏+𝟏
𝒊−𝟏 − (𝒅 + 𝟏)𝒖𝒊 + ( ) 𝒖𝒏+𝟏
𝟐 𝟐 𝟐 𝟐 𝒊+𝟏
𝒅 𝒅
𝑫𝒏 = (𝒅 − 𝟏)𝒖𝒏𝒊 − ( ) 𝒖𝒏𝒊−𝟏 − ( ) 𝒖𝒏𝒊+𝟏
𝟐 𝟐
𝒂 = 𝒅/𝟐 𝒄 = 𝒅/𝟐 𝒃 = −(𝟏 + 𝒅)
Final form of the equation;
𝑫𝒏 = 𝒂𝒖𝒏+𝟏 𝒏+𝟏
𝒊−𝟏 + 𝒃𝒖𝒊 + 𝒄𝒖𝒏+𝟏
𝒊+𝟏
Code:
% SOLUTION OF PDE USING CRANK NICOLSON SCHEME
clear all
clc
Input Data
nu=10; %thermal diffusivity
h=10; %Length of the plate (m)
dy=1; %Grid step size (m)
y=0:dy:h; %y vector
dt=0.02; %Time step size (s)
d=(nu*dt)/(dy)^2; %Diffusion number to check the stability of the solution
n=101; %No. of time steps
t=(n-1)*dt; %Time upto which solution is to be obtained (s)
m=1+h/dy; %No. of spacial nodes in y direction
U=zeros(m,n); %Generating matrix of m*n size
Initial Condition
U(:,1)=0;
Boundary Conditions
U(1,:)=0;
U(end,:)=100;
for k=2:n
for j=2:m-1
if j==2
D(j-1,1)=(-d*U(j-1,k-1))-(1-2*d)*U(j,k-1)-d*U(j+1,k-1)-d*U(j-1,k);
elseif j==m-1
D(j-1,1)= -d*U(j-1,k-1)-(1-2*d)*U(j,k-1)-d*U(j+1,k-1)-d*U(j+1,k);
else
D(j-1,1)=(-d*U(j-1,k-1))-((1-2*d)*(U(j,k-1)))-(d*U(j+1,k-1));
end
end
v=Tridiag(A,B,C,D);
U(2:m-1,k)=v;
end
for k=1:20:n
figure (1)
plot (y,U(1:end,k));
title('Temperature Distributions');
xlabel('y');
ylabel('T');
hold on
end