Lecture 2:
Total RecallMath, Part 2
Ordinary diff. equationsFirst order ODE, one boundary/initial
condition:
Second order ODE
00 )(),,( yxyyxfdx
dy
2
2( , ) ( , )
d y dyf x y g x y
dxdx
ODEs contn’d2nd order ODE can be replaced with a
system of 1st order ODEs:
Typical situation in RT involves two-point boundary conditions
… or initial condition
),( uxhdx
ddx
du
v
g(x)v
1100 )(,)( yxyyxy
'0
0
00 ,)( yxdx
dyyxy
Runge-KuttaFor the 1st order ODE the Euler method
gives:
this also happens to be first order RK scheme
4th order RK:
Note that RK is directly applicable to a system of ODE and therefore to any order ODE with initial conditions
y y x x f x yi i i i i i 1 1( ) ( , )
)(6336
) ,()5.0 ,5.0()5.0 ,5.0(
),(
543211
34
23
12
1
hOkkkk
yy
kyhxfhkkyhxfhkkyhxfhk
yxfhk
ii
ii
ii
ii
ii
Finite-differencesFor the 1st order ODE:
For the 2nd order ODE:
dy
dxf x y
y y x x fx x y y
k k k kk k k k
( , )
( ) ( , )1 11 1
2 2
d y
dxf x y
y yx x
y yx x
x x x xf x y
k k
k k
k k
k k
k k k kk k
2
2
1
1
1
1
1 1
2 2
( , )
( , )
2nd order scheme
For k =1 and k =N equations are given by boundary conditions.
1 1 2, 1 for k k k k k k k k NA y B y C y D
Home work 2a:
Derive the value for coefficients in the numerical scheme above
2
2( ) ( )
d y dyf x g x y
dxdx
This particular form of the 2nd order ODE can be approximated by the
following simple FD scheme:
This numerical scheme results in 3-diagonal matrix:
Solving a system of ODEs leads to a block-diagonal SLE!
RK versus Finite-diff.RK typically has homogeneous convergence, allows higher orders, has good round-off stability (because errors are controlled on every step).High accuracy my be very expensive, specially in multidimensions (fast increase of the number of steps).FD converges (if it does) much faster. More complex schemes (2nd order and higher) gain stability and convergence speed.Expensive and difficult to check maximum error.
Cook-book: to study solution locally when you have time use RK. When high accuracy must be combined with high performance use FD.
Partial Differential Equations
PDEs come in three flavors: hyperbolic, parabolic, and elliptic
A typical example of a hyperbolic equation is a wave equation:
where v is the velocity of wave propagation
2
22
2
2
x
u
t
u
v
PDEs examplesAn example of parabolic equation is the diffusion equation:
where D(>0) is the diffusion coefficient
x
u
xt
uD
PDEs examplesPoisson equation is an example of elliptic type:
where ρ is the source function (density of charges). If ρ is zero for the whole domain we get a special case of Laplace equation
),(2
2
2
2
yxy
u
x
u
Numerical schemesNumerically, the first two types are initial value problems (Cauchy problems):
Initial values
Bou
ndar
y co
nditi
ons
Boundary conditions
Numerical schemesAn elliptic equation is a boundary condition problem:
Boundary conditions
Numerical scheme forPoisson equation
Assuming an equispaced rectangular grid in 2D with stepsize Δ:
In matrix form the scheme looks like this:
which is a 5-diagonal SLE
jijijijijijiji uuuuuu
,2
1,,1,
2
,1,,1 22
kkkkNkNk uuuuuxx
211)1(1 4
Boundaries andgeneralizationThe scheme on the previous slide only
holds inside the domain. The points for
i = 1, Nx and j = 1, Ny are described by the
boundary conditions leading to a system of linear equation Au = b.
In our case, elements on each diagonal of A are constant. In general case, matrix elements along diagonals change.
In 3D more diagonals are present.
Convergence and stabilityApproximation – the accuracy of
approximation of the analytical equation(s) by numerical scheme.
Convergence - the property of the numerical scheme to get closer to the exact solution when the grid becomes denser in some regular way.
Stability - the stability of numerical scheme characterizes the way errors (e.g. finite difference approximation of derivatives) are accumulated during the integration. Stability of the computer implementation of numerical scheme are the way round-off errors are accumulated.
Computational errorsFloating point numbers are stored in 32- or
64-bit long words (IEEE): 01101000011011011110111001000011
11000000110100001011101001000100010111110111100...
Multiplications/divisions do not loose much precision but subtraction/addition is a danger
sign
sign
expo
nent
expo
nent
man
tiss
a
man
tiss
a
HOME WORK 2b: convergence Numerical differentiating:
Is there an optimal ?
1 1
1 1
; ?limi 1 i
i i i i
x xi i i i
y y y ydy
dx x x x x
Diffusion equationInitial value problem:
can be approximated as:
11 1
2
1 1 11 1
2
2
2
j j j j ji i i i i
j j ji i i
u u u u uD
t x
u u u
x
2
2
u uD
t x
i-1 i i+1 i-1 i i+1
Space
j T
ime
j+1 Explicit Implicit
Stability analysis of numerical schemesWe represent the approximation errors our
solution ulm with Fourier components:
Substituting individual components to the finite difference scheme we find the condition that results in corresponding to the unlimited error growth. For the diffusion equation this condition is: Courant condition
m m m am t ikl xl l l m k
k
u u u e v e
2
D tC
x
1 1m ml lu u
Explicit or implicit?New sense of stability: how dramatic will
be the solution after many time steps if we change the initial conditions a little bit?
Explicit schemes (α=1, β=0) tend to have better convergence
Purely implicit schemes (α=0, β=1) tend to be more stable
Combining the two (α>0, β>0) helps to get the optimal scheme
Integration: Gauss quadraturesFor any “reasonable” function f(x) the
integral with kernel K(x) can be approximated as a sum of function values
in nodes xi multiplied by weights.
If f(x) can be represented with orthogonal polynomials exactly, the quadrature formula is also exact.
)()()(N
1i
a
b ii xfdxxfxK
Non-linear equationsFor system of non-linear equations weoften use Newton-Raphson scheme:
Home work 2:c. Write a simple program for 4x4
matrix inversion with Gauss-Jordan elimination and partial pivoting. Test round-off stability by doing many inversions of a random 4 by 4 matrix.
d. Propose the scheme (flow chart) for solving SLE with 4x4 block-diagonal matrix
e. Write (or use NR routine) 4th order RK and FD scheme for the equation:2
32
; (0) 1; (15) 10d y xy e y ydx