Sunteți pe pagina 1din 36

Review

Finite Difference
Solving Finite Difference Problems
Summary

BVP S – F INITE D IFFERENCE T ECHNIQUE

Dr. Johnson

School of Mathematics

Semester 1 2008

Dr. Johnson MATH65241


Review
Finite Difference
Solving Finite Difference Problems
Summary

O UTLINE

1 R EVIEW

2 F INITE D IFFERENCE
Discretising the Problem

3 S OLVING F INITE D IFFERENCE P ROBLEMS


Iterative Methods
Linearisation
Direct Methods

4 S UMMARY

Dr. Johnson MATH65241


Review
Finite Difference
Solving Finite Difference Problems
Summary

O UTLINE

1 R EVIEW

2 F INITE D IFFERENCE
Discretising the Problem

3 S OLVING F INITE D IFFERENCE P ROBLEMS


Iterative Methods
Linearisation
Direct Methods

4 S UMMARY

Dr. Johnson MATH65241


Review
Finite Difference
Solving Finite Difference Problems
Summary

O UTLINE

1 R EVIEW

2 F INITE D IFFERENCE
Discretising the Problem

3 S OLVING F INITE D IFFERENCE P ROBLEMS


Iterative Methods
Linearisation
Direct Methods

4 S UMMARY

Dr. Johnson MATH65241


Review
Finite Difference
Solving Finite Difference Problems
Summary

O UTLINE

1 R EVIEW

2 F INITE D IFFERENCE
Discretising the Problem

3 S OLVING F INITE D IFFERENCE P ROBLEMS


Iterative Methods
Linearisation
Direct Methods

4 S UMMARY

Dr. Johnson MATH65241


Review
Finite Difference
Solving Finite Difference Problems
Summary

M ULTIPLE S HOOTING AND E XTRAPOLATION

If we have a vector of guesses, the correction can be


written as:

dg = −J−1 (g )φ(g )

We can use either the Secant method or solve the


augmented system to generate the Jacobian J.
If we know the order of a scheme, we can exploit it to
generate better approximations at low expense.
The general formula for Richardson extrapolation is:
³ ´
h
km A k − A(h)

A (h) = m
k −1
Dr. Johnson MATH65241
Review
Finite Difference
Solving Finite Difference Problems
Summary

M ULTIPLE S HOOTING AND E XTRAPOLATION

If we have a vector of guesses, the correction can be


written as:

dg = −J−1 (g )φ(g )

We can use either the Secant method or solve the


augmented system to generate the Jacobian J.
If we know the order of a scheme, we can exploit it to
generate better approximations at low expense.
The general formula for Richardson extrapolation is:
³ ´
h
km A k − A(h)

A (h) = m
k −1
Dr. Johnson MATH65241
Review
Finite Difference
Discretising the Problem
Solving Finite Difference Problems
Summary

O UTLINE

1 R EVIEW

2 F INITE D IFFERENCE
Discretising the Problem

3 S OLVING F INITE D IFFERENCE P ROBLEMS


Iterative Methods
Linearisation
Direct Methods

4 S UMMARY

Dr. Johnson MATH65241


Review
Finite Difference
Discretising the Problem
Solving Finite Difference Problems
Summary

T HE P ROBLEM

Let us consider

d2 y
µ ¶
1 dy
= 32 + 2x3 − y , 1 ≤ x ≤ 3,
dx2 8 dx

with the boundary conditions

43
y(1) = 17, y(3) = 3.

The solution y satisfies the equation for every 1 ≤ x ≤ 3.


The exact solution is y(x) = x2 + (16/x).

Dr. Johnson MATH65241


Review
Finite Difference
Discretising the Problem
Solving Finite Difference Problems
Summary

T HE P ROBLEM

Let us consider

d2 y
µ ¶
1 dy
= 32 + 2x3 − y , 1 ≤ x ≤ 3,
dx2 8 dx

with the boundary conditions

43
y(1) = 17, y(3) = 3.

The solution y satisfies the equation for every 1 ≤ x ≤ 3.


The exact solution is y(x) = x2 + (16/x).

Dr. Johnson MATH65241


Review
Finite Difference
Discretising the Problem
Solving Finite Difference Problems
Summary

D ISCRETISATION

Define a uniform grid (x0 , x1 , . . . , xn ) with n + 1 points.


Grid spacing h = (xn − x0 )/n, with xj = x0 + jh, for
j = 0, 1, . . . , n.
Find a relationship between wi and surrounding points

wi = f(wi ,wi−1,w i+1 ) wn


w0

wi−1 wi+1
wi
h
a b

x0 x1 x2 ... xi ... xn

Dr. Johnson MATH65241


Review
Finite Difference
Discretising the Problem
Solving Finite Difference Problems
Summary

D ISCRETISATION

Define a uniform grid (x0 , x1 , . . . , xn ) with n + 1 points.


Grid spacing h = (xn − x0 )/n, with xj = x0 + jh, for
j = 0, 1, . . . , n.
Find a relationship between wi and surrounding points

wi = f(wi ,wi−1,w i+1 ) wn


w0

wi−1 wi+1
wi
h
a b

x0 x1 x2 ... xi ... xn

Dr. Johnson MATH65241


Review
Finite Difference
Discretising the Problem
Solving Finite Difference Problems
Summary

A PPROXIMATING D ERIVATIVES

Approximate y at each of the nodes x = xi by wi


The derivatives of y in the ODE are approximated in
finite-difference form as:
¯
dy ¯¯ w − wi−1
= i+1 + O(h2 ),
dx x=xi
¯ 2h

and

d2 y ¯¯
¯
w − 2wi + wi−1
2
= i+1 + O ( h2 ) .
dx x=xi
¯ h2

Dr. Johnson MATH65241


Review
Finite Difference
Discretising the Problem
Solving Finite Difference Problems
Summary

A PPROXIMATING D ERIVATIVES

Approximate y at each of the nodes x = xi by wi


The derivatives of y in the ODE are approximated in
finite-difference form as:
¯
dy ¯¯ w − wi−1
= i+1 + O(h2 ),
dx x=xi
¯ 2h

and

d2 y ¯¯
¯
w − 2wi + wi−1
2
= i+1 + O ( h2 ) .
dx x=xi
¯ h2

Dr. Johnson MATH65241


Review
Finite Difference
Discretising the Problem
Solving Finite Difference Problems
Summary

A PPROXIMATING D ERIVATIVES

We can generate the approximations by adding and


subtracting Taylor series approximations around xi
For yi+1 we have

1 2 d2 y ¯¯
¯ ¯
dy ¯¯
yi+1 = yi + h ¯ + h +...
dx x=xi 2 dx2 ¯x=xi

and for yi−1 we have

1 2 d2 y ¯¯
¯ ¯
dy ¯¯
yi−1 = yi − h ¯ + h −...
dx x=xi 2 dx2 ¯x=xi

Dr. Johnson MATH65241


Review
Finite Difference
Discretising the Problem
Solving Finite Difference Problems
Summary

A PPROXIMATING D ERIVATIVES

We can generate the approximations by adding and


subtracting Taylor series approximations around xi
For yi+1 we have

1 2 d2 y ¯¯
¯ ¯
dy ¯¯
yi+1 = yi + h ¯ + h +...
dx x=xi 2 dx2 ¯x=xi

and for yi−1 we have

1 2 d2 y ¯¯
¯ ¯
dy ¯¯
yi−1 = yi − h ¯ + h −...
dx x=xi 2 dx2 ¯x=xi

Dr. Johnson MATH65241


Review
Finite Difference
Discretising the Problem
Solving Finite Difference Problems
Summary

T HE D ISCRETISED P ROBLEM

Replace y and it’s derivatives in the ODE by


approximations:

x3i
µ ¶
wi+1 − 2wi + wi−1 wi+1 − wi−1
= 4 + − wi ,
h2 4 16h

for i = 1, 2, . . . , n − 1.
Boundary conditions are w0 = 17 and wn = 43/3.
These equations are nonlinear.

Dr. Johnson MATH65241


Review
Finite Difference
Discretising the Problem
Solving Finite Difference Problems
Summary

T HE D ISCRETISED P ROBLEM

Replace y and it’s derivatives in the ODE by


approximations:

x3i
µ ¶
wi+1 − 2wi + wi−1 wi+1 − wi−1
= 4 + − wi ,
h2 4 16h

for i = 1, 2, . . . , n − 1.
Boundary conditions are w0 = 17 and wn = 43/3.
These equations are nonlinear.

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

O UTLINE

1 R EVIEW

2 F INITE D IFFERENCE
Discretising the Problem

3 S OLVING F INITE D IFFERENCE P ROBLEMS


Iterative Methods
Linearisation
Direct Methods

4 S UMMARY

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

S OLVING A NONLINEAR PROBLEM

Given such an equation we may iterate toward the


solution.
(k )
Let wi be the kth iteration at xi .

We wish to rearrange with all w(k) ’s on the LHS;

(k −1) (k −1)
à !
1 (k ) wi+1 − wi−1 2 (k ) 1 (k ) x3i
w + − 2 wi + w = 4 + ,
h2 i+1 16h h h2 i−1 4

Cannot solve if there is w(k) multiplied by a w(k) . . .


so some w’s moved to the LHS must be k − 1, i.e. already be
known

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

S OLVING A NONLINEAR PROBLEM

Given such an equation we may iterate toward the


solution.
(k )
Let wi be the kth iteration at xi .

An alternative rearrangement may be;

(k −1) (k −1)
à ! à !
1 w (k ) 2 (k ) 1 w (k ) x3i
2
+ i wi+1 − 2 wi + 2
− i wi−1 = 4 +
h 16h h h 16h 4

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

O UTLINE

1 R EVIEW

2 F INITE D IFFERENCE
Discretising the Problem

3 S OLVING F INITE D IFFERENCE P ROBLEMS


Iterative Methods
Linearisation
Direct Methods

4 S UMMARY

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

N EWTON L INEARISATION
Suppose that we have a guess for the solution Wi ∼ wi .
Seek a correction δwi such that wi = Wi + δwi satisfies the
system.
Substituting wi = Wi + δwi into equations and linearising
gives:

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

N EWTON L INEARISATION
Suppose that we have a guess for the solution Wi ∼ wi .
Seek a correction δwi such that wi = Wi + δwi satisfies the
system.
Substituting wi = Wi + δwi into equations and linearising
gives:

δwi+1 − 2δwi + δwi−1


= Fi
h2 µ ¶
Wi+1 − Wi−1
− δwi
16h
µ ¶
δwi+1 − δwi−1
− Wi + O(δw2 )
16h

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

N EWTON L INEARISATION
Suppose that we have a guess for the solution Wi ∼ wi .
Seek a correction δwi such that wi = Wi + δwi satisfies the
system.
Substituting wi = Wi + δwi into equations and linearising
gives:

µ ¶ µ ¶
1 W Wi+1 − Wi−1 2
2
+ i δwi+1 + − 2 δwi
h 16h 16h h
µ ¶
1 W
+ − i δwi−1 = Fi + O(δw2 )
h2 16h

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

N EWTON L INEARISATION
Suppose that we have a guess for the solution Wi ∼ wi .
Seek a correction δwi such that wi = Wi + δwi satisfies the
system.
Substituting wi = Wi + δwi into equations and linearising
gives:

x3
µ ¶
Wi+1 − Wi−1 Wi+1 − 2Wi + Wi−1
Fi = 4 + i − Wi − ,
4 16h h2

When Fi = 0 the system is solved. This is like our φ from


before.

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

O UTLINE

1 R EVIEW

2 F INITE D IFFERENCE
Discretising the Problem

3 S OLVING F INITE D IFFERENCE P ROBLEMS


Iterative Methods
Linearisation
Direct Methods

4 S UMMARY

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

G ENERAL SYSTEM OF EQUATIONS

Both of the methods above lead to a tridiagonal system of


linear equations of the form

αi ui−1 + β i ui + γi ui+1 = δi , i = 0, 1, . . . , n.

where αi , β i , γi , and δi are the coefficients from the


difference equation.
For example previously we had:

1 Wi Wi + 1 − W i − 1 2 1 Wi
αi = h2
+ 16h , βi = 16h − h2
, γi = h2
− 16h , and δi = Fi .

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

G ENERAL SYSTEM OF EQUATIONS

Both of the methods above lead to a tridiagonal system of


linear equations of the form

αi ui−1 + β i ui + γi ui+1 = δi , i = 0, 1, . . . , n.

where αi , β i , γi , and δi are the coefficients from the


difference equation.
For example previously we had:

1 Wi Wi + 1 − W i − 1 2 1 Wi
αi = h2
+ 16h , βi = 16h − h2
, γi = h2
− 16h , and δi = Fi .

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

G ENERAL SYSTEM OF EQUATIONS

In matrix form, we are solving

Au = b
and the solution is

u = A−1 b

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

T HOMAS ’ S TRIDIAGONAL ALGORITHM

The matrix A looks like

 
β 0 γ0
 α1 β 1 γ1 
 

 α2 β 2 γ2 

A=
 .. .. .. 
 . . . 


 α n−2 β n−2 γn−2


 αn−1 β n−1 γn−1 
αn βn

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

T HOMAS ’ S TRIDIAGONAL ALGORITHM

The Thomas algorithm is based on Gaussian elimination

 
β 0 γ0
 α1 β 1 γ1 
 

 α2 β 2 γ2 

A=
 .. .. .. 
 . . . 


 α n−2 β n−2 γn−2


 αn−1 β n−1 γn−1 
αn βn

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

T HOMAS ’ S TRIDIAGONAL ALGORITHM

1. Create zeros below the diagonal

 
β 0 γ0
 0 β 1 γ1 
 

 0 β2 γ2 

A=
 .. .. .. 
 . . . 


 0 β n−2 γn−2 

 0 β n−1 γn−1 
0 βn

Dr. Johnson MATH65241


Review
Iterative Methods
Finite Difference
Linearisation
Solving Finite Difference Problems
Direct Methods
Summary

T HOMAS ’ S TRIDIAGONAL ALGORITHM

1. Create zeros below the diagonal


2. Back substitute

 
β 0 γ0
 0 β 1 γ1 
 

 0 β2 γ2 

A=
 .. .. .. 
 . . . 


 0 β n−2 γn−2 

 0 β n−1 γn−1 
0 βn

Dr. Johnson MATH65241


Review
Finite Difference
Solving Finite Difference Problems
Summary

Finite difference solutions are normally the preferred


method when
Boundary conditions at both ends,
The problem is second order.
We have used three point approximations to get second
order truncation.
This can be extended to higher order but at great expense.
We reduce problems to the form:

αi ui−1 + β i ui + γi ui+1 = δi , i = 0, 1, . . . , n.

From which we can use a direct method to solve

Dr. Johnson MATH65241


Review
Finite Difference
Solving Finite Difference Problems
Summary

Finite difference solutions are normally the preferred


method when
Boundary conditions at both ends,
The problem is second order.
We have used three point approximations to get second
order truncation.
This can be extended to higher order but at great expense.
We reduce problems to the form:

αi ui−1 + β i ui + γi ui+1 = δi , i = 0, 1, . . . , n.

From which we can use a direct method to solve

Dr. Johnson MATH65241

S-ar putea să vă placă și