You are on page 1of 3

Five points finite difference method

Changchun Wang Feb 12, 2008

Mathematical Notation

We will try to find the numerical solution of the following Laplace equation:
u(x, y) = f (x, y), u(x, y) (0, 1) (0, 1)
u(x, y) = 0, u(x, y) [0, 1] [0, 1]

(1)

Here u(x, y) is defined as:


u(x, y) =

2 u(x, y) 2 u(x, y)
+
x2
y 2

(2)

and
u(x, y)
u(x + h, y) u(x, y)
= lim
h0
x
h
2
( u(x,y)
u(x, y)
x )
=
2
x
x

(3)

Finite difference approximation

The basic idea of finite difference method is using finite difference to approximate differential. That is,
u(x, y)
u(x + h, y) u(x, y)

x
h
u(x, y)
u(x, y + h) u(x, y)

y
h

(4)

when h is small.
For high order:
u(x+h,y)u(x,y)
u(x,y)u(xh,y)
2 u(x, y)
h
h

x2
h
u(x + h, y) + u(x h, y) 2u(x, y)
=
h2
2
u(x, y)
u(x, y + h) + u(x, y h) 2u(x, y)

2
y
h2

(5)

And u(x, y) can be approximated as:


2 u(x, y) 2 u(x, y)
+
x2
y 2
u(x + h, y) + u(x h, y) + u(x, y + h) + u(x, y h) 4u(x, y)

h2
u(x, y) =

(6)

Assemble the matrix


4*4 grids

1
0.9
(1,1) 1

0.8

(1,2) 2

(1,3) 3

0.7
0.6

(2,2) 5

(2,1) 4

(2,3) 6

0.5
0.4
(3,1) 7

0.3

(3,2) 8

(3,3),9

0.2
0.1
0

0.2

0.4
0.6
n=3, h=1/(n+1)=1/4

0.8

Figure 1: Example of mesh n=3

First set U(i,j) to be the numerical approximation of u(x, y) at node (i, j). On the
boundary the value of U(i,j) is simply zero and for node in the middle we have:
h2 f(i,j) = 4U(i,j) U(i+1,j) U(i1,j) U(i,j+1) U(i,j1)

(7)

For instance, in the figure, at point (1, 1) we get the equation


h2 f(1,1) = 4U(1,1) U(2,1) U(1,2)

(8)

and at point (2, 2) we get equation


h2 f(2,2) = 4U(2,2) U(3,2) U(1,2) U(2,3) U(2,1)

(9)

To assemble the matrix, we need a new index for nodes. As in the figure, set (1, 1) to
1, (1, 2) to 2, ... (3, 3) to 9. Now we get for equation (8) and (9):
h2 f1 = 4U1 U4 U2

(10)

h2 f5 = 4U5 U8 U2 U6 U4

(11)

In matrix form

A=

4 1 0 1 0
0
0
0
0
1 4 1 0 1 0
0
0
0

0 1 4
0
0 1 0
0
0

1 0
0
4 1 0 1 0
0

0 1 0 1 4 1 0 1 0

0
0 1 0 1 4
0
0 1

0
0
0 1 0
0
4 1 0

0
0
0
0 1 0 1 4 1
0
0
0
0
0 1 0 1 4

b=

F =

U1
U2
U3
U4
U5
U6
U7
U8
U9
f1
f2
f3
f4
f5
f6
f7
f8
f9

A b = h2 F

(12)

Solve the linear system

There are many ways to solve the system we got. Gauss-elimination, LU decomposition,
and iteration methods. The detail will be discuss later.

You might also like