0% found this document useful (0 votes)
83 views8 pages

Numerical Solution To PDEs

The document discusses solving the 1D heat equation using two numerical methods: the explicit FTCS method and the implicit Crank-Nicolson method. Code is provided to implement both methods. The FTCS method is shown to be stable and its solution is plotted. For the Crank-Nicolson method, the tridiagonal matrix formulation is derived and code is provided to solve the system of equations implicitly.

Uploaded by

Zohaib Altaf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views8 pages

Numerical Solution To PDEs

The document discusses solving the 1D heat equation using two numerical methods: the explicit FTCS method and the implicit Crank-Nicolson method. Code is provided to implement both methods. The FTCS method is shown to be stable and its solution is plotted. For the Crank-Nicolson method, the tridiagonal matrix formulation is derived and code is provided to solve the system of equations implicitly.

Uploaded by

Zohaib Altaf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Assignment No.

Solving PDE’s Using PSOR, FTCS Explicit


and Crank Nicolson Implicit Schemes
Advanced Numerical Methods

Zohaib Altaf (195108)


Nasir Iqbal (195102)
Zain Javed (195104)
Table of Contents
1. Problem Statement ................................................................................................................... 2
Question No. 1 ............................................................................................................................ 2
2. FTCS Explicit Solution To 1-D Heat Equation ....................................................................... 3
Code ............................................................................................................................................ 3
Input Data.................................................................................................................................... 4
Initial Condition .......................................................................................................................... 4
Boundary Conditions .................................................................................................................. 4
Explicit Solution to The Problem ............................................................................................... 4
3. The Crank Nicolson’s Solution to 1-D Heat Equation ............................................................ 5
Code: ........................................................................................................................................... 6
Input Data.................................................................................................................................... 6
Initial Condition .......................................................................................................................... 6
Boundary Conditions .................................................................................................................. 6
Implicit Solution to The Problem ............................................................................................... 6
1. PROBLEM STATEMENT

Question No. 1
Solve the 1-D heat equation that can represented by the governing equation

Using following solution schemes;

I: Explicit FTCS
II: Crank Nicolson Implicit Scheme

Where; 𝑢 (𝑡, 𝑦) is the temperature. Assume initial and boundary conditions ;

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

Which is of order [(Δt), (Δy)2]. Here the diffusion term is;


Δt
𝑑=𝑣 =0.2
Δ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;

Explicit Solution to The Problem


for k=2:n
for j=2:m-1
U(j,k)=U(j,k-1)+d*(U(j+1,k-1)-2*U(j,k-1)+U(j-1,k-1));
end
end

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

D=zeros(m-2,1); %Generating RHS (D) matrix of (m-2)*1 size


B=zeros(m-2,1); %Generating diagonal B entries of (m-2)*1 size
A=zeros(m-2,1); %Generating subdiagonal A entries of (m-2)*1 size
C=zeros(m-2,1); %Generating superdiagonal C entries of (m-2)*1 size

Initial Condition
U(:,1)=0;

Boundary Conditions
U(1,:)=0;
U(end,:)=100;

Implicit Solution to The Problem


A(2:m-2,1)=d;
C(1:m-3,1)=d;
B(1:m-2,1)=-(1+2*d);

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

Published with MATLAB® R2017b

You might also like