Finite Difference Method To Solve The

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

QUAID-E-AZAM COLLEGE OF ENGINEERING AND TECHNOLOGY

SAHIWAL

AFFILIATED WITH
UNIVERSITY OF ENGINEERING AND TECHNOLOGY LAHORE

CIVIL ENGINEERING DEPARTMENT

SUBJECT:
NUMERICAL ANYLISIS LAB(MA-240)

TOPIC:
FINITE DIFF METHOD FOR PDE’s

SUBMITTED BY:
USMAN MUHEEB [2019-UET-QET-SWL-CIVIL-68]

SEMESTER & SESSION:


3RD(2019-2023)
Finite Difference Method:

In numerical analysis, finite-difference methods (FDM) are a class of numerical techniques for


solving differential equations by approximating derivatives with finite differences. Both the
spatial domain and time interval (if applicable) are discretized, or broken into a finite number of
steps, and the value of the solution at these discrete points is approximated by solving algebraic
equations containing finite differences and values from nearby points.

Finite difference methods convert ordinary differential equations (ODE) or partial differential


equations (PDE), which may be nonlinear, into a system of linear equations that can be solved by
matrix algebra techniques. Modern computers can perform these linear algebra computations
efficiently which, along with their relative ease of implementation, has led to the widespread use
of FDM in modern numerical analysis.[1] Today, FDM are one of the most common approaches
to the numerical solution of PDE, along with finite element methods.[1]

Numerical Methods for Solving PDEs:


Numerical methods for solving different types of PDE's reflect the different character of the problems.

• Laplace
solve all at once for steady state conditions

• Parabolic

(heat) and Hyperbolic (wave) equations. Integrate initial conditions forward through
time.

Methods:

• Finite Difference (FD) Approaches:

Based on approximating solution at a finite # of points, usually arranged in a regular grid.

• Finite Element (FE) Method:

Based on approximating solution on an assemblage of simply shaped (triangular, quadrilateral)


finite pieces or "elements" which together make up (perhaps complexly shaped) domain.
Finite Difference for Method Solving PDE's:

Solving PDE's:

• Solve all at once


• Liebmann Method:
– Based on Boundary Conditions (BCs) and finite difference approximation to formulate system
of equations
– Use Gauss-Seidel to solve the system

∂2 U ∂2 U ∂U ∂U
2 + 2 = -D( x, y, u, + )
∂x ∂y ∂x ∂y

Problem:
Consider the isothermal packed-bed reactor. The governing differential equation

1 d2 y dy
Np dx 2 + dx
R y n= g(x)

is subject to the boundary conditions

1 d y ( 0)
y 0 (0) = 0, y(1) + N =1
p dx

Maximum absolute errors in both y and y 0 for different values of Npe, order n of reaction and
the range of values of R with the exact solution
2 3

y(x) = N pe e (x − x ) /( N pe − 1.0)

Results:
h
8 16 32 64 128 256
y .116733(-1) .339170(-2) .931260(-3) .245032(-3) .629093(-4) .159420(-4)
y’ .309695(-1) .828688(-2) .269651(-2) .753022(-3) .198104(-3) .507542(-4)
N = 2, R = 1/8, Npe = 2
y .136306(1) .402905(-2) .111447(-3) .294187(-3) .756419(-4) .191822(-4)
y’ .31777(1) .777896(-2) .251621(-3) .704275(-3) .185440(-4) .475274(-4)
Coding:

%%% Finite difference method to solve the


%%% parabolic boundary value problem
%%% u_t(x,t)-u_xx(x,t)+a(x)u_x(x,t)+alpha(x)u(x-delta,t)+beta(x)(x,t)+gama(x)u(x+eta,t)=f(x,t)
%%% on (0,1)x(0,T]
%%% subject to the initial condition u(x,0)=0;
%%% and boundary conditions u(0,t)=u(1,t) = 0;
%clc;
%clear all;
%close all
%% Problem Data
% simple example
f = inline('10*t.^2.*exp(-t).*x.*(1-x)'); % source function
ax= inline('2-x.^2'); % coefficent of convection term
alpha=inline('-2+x.*0');% coefficient of reaction term
beta = inline('x+4');% coefficient of reaction term
omega = inline('-1+x.*0');% coefficient of reaction term
%%
%%Data for numerical method
N = 30; % Number of points in space
M = 2^4; % Number of points in time
T = 1;
phi=0;
psi=0;
%%
%% Set up the mesh
h = 1/N;
hh=h.^2;
x = linspace(0,1,N+1)';
tau = T/M;
t=linspace(0,T,M+1);
[X,Y] = meshgrid(x,t);
%%
U = zeros(M+1, N+1)+NaN;
U(1,:)=0; % initial condition
U(:,1)=phi; % left boundary condition
U(:,N+1)=psi; % right boundary condition
%% Construct the Linear System
p=5; s=N-(N-5);
A(1,1)=1; A(N+1,N+1)=1;
for i=2:N
if i<=p
A(i,i-1)=-1/hh-ax(x(i))/h;
A(i,i)=2/hh+ax(x(i))/h+ beta(x(i))+omega(x(i));
A(i,i+1)=-1/hh;
elseif i<=N-l;
A(i,i-1)=-1/hh-ax(x(i))/h;
A(i,i)=2/hh+ax(x(i))/h+ beta(x(i))+alpha(x(i))*U(j,i-p)+omega(x(i))*U(j,i+s);
A(i,i+1)=-1/hh;
else
A(i,i-1)=-1/hh-ax(x(i))/h;
A(i,i)=2/hh+ax(x(i))/h+ beta(x(i))+alpha(x(i));
A(i,i+1)=-1/hh;
end
end
%spy(A);
for j=2:M+1
if i<=p
F = [phi; tau*f(x(i),t(j)) + U(j-1,2:N)'; psi];
elseif i<=N-l;
F = [phi; tau*f(x(i),t(j)) + U(j-1,2:N)'; psi];
else
F = [phi; tau*f(x(i),t(j)) + U(j-1,2:N)'; psi];
end
U(j,:) = (eye(N+1)+tau*A)\F;

end
figure(2); mesh(X,Y,U); hold on
figure(3);plot(X,U(j,:)); hold on
for j=2:M
for i=2:N
numsol(j,i)=U(j,i);
end
end
%%
Flowchart:

You might also like