Processing math: 100%

Ramjee Sharma
Professor of Mathematics
Department of Mathematics
University of North Georgia
Office: Watkins 190, Gainesville Campus


Numerical Solutions of Partial Differential Equations

First we solve an ordinary differential equaiton d2udx212xu=1

with 0<x<1, along with the boundary conditions u(0)=1 and u(1)=1..

To solve this problem numerically, we divide the interval [0,1] into n equal subintervals with length Δx=xnx0n. For our case Δx=10n=1n. The set of partitioning points or mesh points are given as x0=0

x1=x0+Δx=0+1n=1n
x2=x0+2Δx=2Δx=2n
xi=x0+iΔx=0+in
xn=1
We approximate the terms of the differential equation as follows: u(x)ui
dudxui+1ui12Δx
d2udx2ui+12ui+ui1(Δx)2
u(x0)u0
u(xn)ui
uiu(xi),i=0,1,2,,n
Then our original differential boundary value problem becomes the following n system of equations ui+12ui+ui1(Δx)212xiui=1,i=1,2,,n1
u0=1,un=1
For our purpose we use n=5. Then the above system becomes 25(u22u1+u0)125u1=1
25(u32u2+u1)254u1=1
25(u42u3+u2)365u1=1
25(u52u4+u3)485u1=1
Using the boundary conditions u0=1,un=1 and simplifying, we get 52.4u1+25u2=26
25u154.8u2+25u3=1
25u257.2u3+25u4=1
25u359.6u4=24
We can represent the above system of equations as a matrix equation Au=f
where, A=[52.425002554.825002557.224002559.6]
u=[u1u2u3u4]
and f=[261124]
The solution is u=A1f
The following Python program solves this equaiton.


Heat Equaiton

Consider the one dimensional heat equaiton ut=uxx,0<x<1,0<t,

u(0,t)=0,u(1,t)=0,0<t,
u(x,0)=f(x),0<x<1.

We use the mesh points x0,x1,x2,,xi,,xn

along the spatial direction and the mesh points t0,t1,t2,,tm,
along the time direction. We approximate the solution u(x,t) by u(xi,tm)=ui(m). The partial derivative terms are approximated as ux(xi,tm)ui+1(m)ui1(m)2Δx
2ux2(xi,tm)ui+1(m)2ui(m)+ui1(m)(Δx)2
ut(xi,tm)ui(m+1)ui(m)Δt
Then the above heat equaiton has the following discritized form: ui(m+1)ui(m)Δt=ui+1(m)2ui(m)+ui1(m)(Δx)2,i=1,2,,n1,m=0,1,2,
These equations are solved for ui(m+1) ui(m+1)=rui1(m)+(12r)ui(m)+rui+1(m),
where r=Δt/(Δx)2. This equaiton is valid only for 0<r1/2. This equation can be used to compute ui(m+1) from ui(m) at the preceding time level. As for example, the values of the ui at time level m=1 can be calculated by setting m=0 in the above equation as ui(1)=rui1(0)+(12r)ui(0)+rui+1(0)i=1,2,,n1.
This process can be repeated to compute ui(m) for m=2,3,.

For a special case, we take Δx=1/4 and r=1/2. This will give Δt=1/32. The equations at i=1,2,3 become u1(m+1)=12(u0(m)+u2(m)),

u2(m+1)=12(u1(m)+u3(m)),
u3(m+1)=12(u2(m)+u4(m)).

The following Python program can be used to compute the numerical solutions of the heat equation.


Wave Equaiton

Consider the one dimensional wave equaiton utt=uxx,0<x<1,0<t,

u(0,t)=0,u(1,t)=0,0<t,
u(x,0)=f(x),0<x<1.
ut(x,0)=g(x),0<x<1.

We use the mesh points x0,x1,x2,,xi,,xn

along the spatial direction and the mesh points t0,t1,t2,,tm,
along the time direction. We approximate the solution u(x,t) by u(xi,tm)=ui(m). The partial derivative terms are approximated as ux(xi,tm)ui+1(m)ui1(m)2Δx
2ux2(xi,tm)ui+1(m)2ui(m)+ui1(m)(Δx)2
ut(xi,tm)ui(m+1)ui(m)Δt
2ut2(xi,tm)ui(m+1)2ui(m)+ui(m1)(Δt)2
Then the above wave equaiton has the following discritized form: ui(m+1)2ui(m)+ui(m1)(Δt)2=ui+1(m)2ui(m)+ui1(m)(Δx)2,i=1,2,,n1,m=0,1,2,
After solving these equations for ui(m+1), we get ui(m+1)=ρ2ui1(m)+2(1ρ2)ui(m)+ρ2ui+1(m)ui(m1),
where ρ=Δt/Δx. For each time level, we need the informaiton for two previous levels. From the initial condition, we have ui(0)=f(xi). To get the values of ui(1), we use the condition ut(x,0)=g(x). In deed, using m=0 we get ut=ui(1)ui(1)2Δt=g(x)
This gives us ui(1)ui(1)=2Δtg(x)
Also, using m=0 in ui(m+1)=ρ2ui1(m)+2(1ρ2)ui(m)+ρ2ui+1(m)ui(m1)
and rearranging few terms, we get ui(1)+ui(1)=ρ2f(xi1)+2(1ρ2)f(xi)+ρ2f(xi1)
Solve the above equations for ui(1), we get ui(1)=12ρ2(f(xi1))+(1ρ2)f(xi)+12ρ2f(xi+1)+Δtg(xi)
These equations are valid only for ρ1. The following Python program can be used to solve the one dimensional wave equaiton. For our application, we will use f(x)=2x if 0<x<1/2 and f(x)=2(1x) if 1/2<x<1. Also, we use g(x)=0, n=4, Δx=1/4, and ρ=1.


Two Dimensional Laplace Equaiton

Consider the two dimensional Laplace Equation with the boundary conditions 2ux2+2ux2=0

0<x<1,0<y<1
u(0,y)=0,u(x,0)=0,u(x,1)=50,u(1,y)=50
The difference equaiton becomes ui+1,j2ui,j+ui1,j(Δx)2=ui,j+12ui,j+ui,j1(Δy)2,i=1,2,,n1
Let Δx=Δ
ui+1,j+ui1,j+ui,j+1+ui,j14ui,j=0
For our purpose, let's use n=4. Then we have Δx=14. We will have one equation for each of the nine (i,j)'s as follows: u2,1+u1,24u1,1=0
u3,1+u1,1+u2,24u2,1=0
u4,1+u2,1+u3,143,1=0
u2,2+u1,34u1,2=0
u3,2+u1,2+u2,3+u2,14u2,2=0
u2,2+u3,3+u3,14u3,2=25
u2,3+u3,24u1,3=50
u3,3+u1,3+u2,24u2,3=50
u2,3+u3,24u3,3=75
The above system of 9 equations can be put as a matrix vector equation as Au=f,
where A=[410100000141010000014001000000410100010141010001014001000100410000010141100001014]
u=[u1,1u2,1u3,1u1,2u2,2u3,2u1,3u2,3u3,3]
f=[0000025505075]
The solution is u=A1f
. The following Python program solves this matrix equation.