Lecture 4

EEE 431
Computational Methods in
Electrodynamics
Lecture 4
By
Dr. Rasime Uyguroglu
[email protected]
1
FINITE DIFFERENCE METHODS
2
Introduction






In general real life EM problems cannot be
solved by using the analytical methods,
because:
The PDE is not linear,
The solution region is complex,
The boundary conditions are of mixed types,
The boundary conditions are time dependent,
The medium is inhomogeneous or anisotropic.
3
Introduction



For such complicated problems
numerical methods must be employed.
Finite Difference Method (FDM) is one of
the available numerical methods which
can easily be applied to solve PDE’s with
such complexity.
FDM, is easy to understand and apply.
4
Introduction




FD techniques are based upon approximations
of differential equations by finite difference
equations.
Finite difference approximations:
have algebraic forms,
Relate the value of the dependent variable
at a point in the solution region to the values at
some neighboring points.
5
Introduction




Steps of finite difference solution:
Divide the solution region into a grid of
nodes,
Approximate the given differential
equation by finite difference equivalent,
Solve the differential equations subject
to the boundary conditions and/or initial
conditions.
6
Introduction

Rectangular Grid Pattern
7
Finite Difference Schemes

The derivative of a given function f(x)
can be approximated as:
df ( x0 )
dx
df ( x0 )
dx
df ( x0 )
dx
f ( x0  x)  f ( x0 )
(1)
x
f ( x0 )  f ( x0  x)
(2)
x
f ( x0  x)  f ( x0  x)
(3)
2x
Forward Difference Formula
Backword Difference Formula
Central Difference Formula
8
Finite Difference Schemes
f(x)
P
B
A
x0  x
x0
x0  x
x
9
Finite Difference Schemes

Estimate of second derivative of f(x) at
P:
x
x
f ( x0 
 f
x 2
2
x
)
2 
f ( x0 
x
2
)
x
1  f ( x0  x)  f ( x0 ) f ( x0 )  f ( x0  x) 



x 
x
x
f ( x0  x)  2 f ( x0 )  f ( x0  x)
(4)
2
( x )
10
Finite Difference Schemes

Or, by using Taylor Series:
2
f ( x0 ) 1
( x)3  3 f ( x0 )
2  f ( x0 )
f ( x0  x )  f ( x0 )  x
 (x)

 ... (5)
2
3
x
2!
3!
x
x
2
f ( x0 ) 1
(x)3  3 f ( x0 )
2  f ( x0 )
f ( x0  x)  f ( x0 )  x
 ( x)

 ... (6)
2
3
x
2!
3!
x
x
11
Finite Difference Schemes

Adding these equations:
 f ( x0 )
4
f ( x0  x)  f ( x0  x)  2 f ( x0 )  (x)

O
(

x
)
2
x
2
2

Assuming that higher order terms are
neglected:
2 f
f ( x0  x)  2 f ( x0 )  f ( x0  x)

2
2
x
(x)
12
Finite Difference Schemes


O(x) 4 is the error introduced by
truncating the series.
It represents the terms that are not
greater than (x) 4 .
13
Finite Difference Schemes

Subtracting Eq.6 from Eq. 5 and
neglecting terms of the order (x)3
f ( x0 )
x


f ( x0  x)  f ( x0  x )
2x
Error is second order.
Eq. 3- Eq.4 are second order, Eq.1 and
Eq. 2 are first order.
14
Finite Difference Schemes

As long as the derivatives of f are well
behaved and the step size is not too
large, the central difference should be
the most accurate of the other two. i.e.
Backward and forward difference
approximations.
15
Finite Difference Schemes


The error in central difference decreases
quadratically as the step size
decreases, whereas the decrease is only
linear for the other two formula.
In general, CDF is to be preferred.
Situations where the data is not available
on both sides of the point where the
numerical derivative is to be calculated
are exceptions.
16
Finite Difference Schemes

To apply the
difference method to
find the solution of a
function  ( x, t ) the
solution region is
divided into
rectangles:
17
Finite Difference Schemes

Let the coordinates (x, t) of a typical grid
point or a node be:
x  ix, i  0,1,2,...
t  jt , j  0,1,2,...

The value of
 at a point:
(i, j )  (ix, jt )
18
Finite Difference Schemes

Using this notation, the central difference
approximations of  at (i, j) are: First
derivative:

x (i , j )

t (i , j )
 (i  1, j )   (i  1, j )
2 x
 (i, j  1)   (i, j  1)
2 t
19
Finite Difference Schemes

Second derivative:
 
2
x (i , j )
 (i  1, j )  2 (i, j )  (i  1, j )
2
(x)
 
t 2 (i , j )
 (i, j  1)  2 (i, j )   (i, j  1)
(t ) 2
2
2
20
Finite Difference Schemes


One dimensional example:
2 f
Solve
x

2
 4 f  0 , 0  x  1.0
Subject to the boundary conditions:
f (0)  0
f (1)  1

Assume
x  0.5
21
Finite Difference Schemes

Solution: Discretization of the equation:
f (i  1)  2 f (i )  f (i  1)
 4 f (i )  0
2
( x )
f (2)  2 f (1)  f (0)
 4 f (1)  0
2
(0.5)
22
Finite Difference Schemes

Since there is one unknown, one
equation is enough to find this unknown.
f (1)  f (0)  f (2)
f (1)  1
23
Finite Difference Schemes

If
x  0.25
f (2)  2 f (1)  f (0)
 4 f (1)  0
2
(0.25)
f (3)  2 f (2)  f (1)
 4 f (2)  0
2
(0.25)
f (4)  2 f (3)  f (2)
 4 f (3)  0
2
(0.25)
24
Finite Difference Schemes

f(1), f(2) and f(3) are unknowns.
Therefore, three equations are written to
find three unknowns.
25
Finite Difference Schemes


For 1  N x we have (N-1) unknowns
and we need (N-1) equations to solve.
The equation of the i th node is:
f (i  1)  2 f (i)  f (i  1)
 4 f (i)  0
2
(x)
26
Finite Differencing of Parabolic
PDE’s

Consider the diffusion equation:
  
k
 2
t
x
2

Where k is a constant. Discretized
equation:
(i, j  1)  (i, j ) (i  1, j )  2(i, j )  (i  1, j )
k

t
(x)2
27
Finite Difference Schemes

Where
x  ix, i  0,1, 2,..., n
t  j t , j  0,1, 2,..., n


Forward difference for t and central
difference for x is used.
Let:
t
r
2
k (x)
28
Finite Difference Schemes

We can write:
(i, j  1)  r(i  1, j )  (1  2r )(i, j )  r(i  1, j )



This equation can be calculated in terms
of boundary and initial conditions.
This explicit formula can be used to find
( x, t  t ) explicitly in terms of  ( x, t ) .
29
Stability



Stability is important for the numerical
solutions.
A stable solution is only possible when
(1-2r) is nonnegative. Or: 0  r  1
2
Choose r=1/2. Then our equation
becomes:
1
 (i, j  1)    (i  1, j )   (i  1, j ) 
2
30
Stability

Stability increases by applying an implicit
formula. The formula is simple to apply
but it is computationally slow. Crank and
Nicholson’s formula:
 (i, j  1)   (i, j ) 1  (i  1, j )  2 (i, j )   (i  1, j )
k
 {
t
2
( x ) 2
 (i  1, j  1)  2 (i, j  1)   (i  1, j  1)

}
2
( x )
31
Example (Cont.)

Rewrite:
r(i  1, j  1)  2(1  r )(i, j  1)  r(i  1, j  1)
 r(i  1, j )  2(1  r )(i, j )  r(i  1, j )

Three known values on the left hand
side and three unknown values on the
right hand side.
32
Example (cont.)

The formula is valid for all finite values of
r, chose r=1:
(i  1, j  1)  4(i, j  1)  (i  1, j  1)  (i  1, j )  (i  1, j )
33