Professional Documents
Culture Documents
umberto.biccari@deusto.es enrique.zuazua@fau.de
cmc.deusto.es dcn.nat.fau.eu
One of the simplest and of the oldest methods to solve differential equations.
It was already known by Euler, in one space-dimension, and extended to
dimension two by Runge (ca. 1908).
The advent of finite difference techniques in numerical applications began
in the early 1950s and their development was stimulated by the emergence
of computers that offered a convenient framework for dealing with complex
problems of science and technology.
2 / 64
Finite difference approximation of derivatives
3 / 64
Finite difference approximation
The main concept behind any finite difference scheme is related to the definition of
the derivative of a smooth function f at a point x ∈ R
1
f 0 (x) = lim f (x + h) − f (x) .
h→0 h
When h tends to 0 (without vanishing), the quotient on the right-hand side provides a
good approximation of the derivative.
4 / 64
Approximation error
Approximation error
We deduce that
|u00 (y)|
1
Eh := f (x + h) − f (x) − f 0 (x) ≤ Ch,
with C= sup
h y∈[x,x+h] 2
Order of approximation
6 / 64
Approximation error
Backward difference
7 / 64
Central difference
In order to improve the accuracy, we can consider the central difference approxi-
mation of f 0 , by taking the points x − h and x + h into account.
Suppose that the function f is C3 in the vicinity of x. By subtracting the two expressions
f 00 (x) 2 f 000 (ξ + ) 3
f (x + h) = f (x) + f 0 (x)h + h + h , ξ + ∈ (x, x + h)
2 6
f 00 (x) 2 f 000 (ξ − ) 3
f (x − h) = f (x) − f 0 (x)h + h − h , ξ + ∈ (x − h, x)
2 6
we get
Central difference
1 f 000 (ξ) 2
∂h f (x) = f (x + h) − f (x − h) = f 0 (x) + h , ξ ∈ (x − h, x + h).
2h 3
8 / 64
Approximation error
Remark
9 / 64
Example - forward finite difference for f (x) = sin(x)
1
f (x) = sin(x) f 0 (x) = cos(x) ∂h+ = f (x + h) − f (x)
h
10 / 64
Example - forward finite difference for f (x) = sin(x)
1
f (x) = sin(x) f 0 (x) = cos(x) ∂h+ = f (x + h) − f (x)
h
h Eh
1.2566 0.5981
0.6283 0.3090
0.3142 0.1558
0.1257 0.0628
0.0628 0.0314
11 / 64
Example - central finite difference for f (x) = sin(x)
1
f (x) = sin(x) f 0 (x) = cos(x) ∂h = f (x + h) − f (x − h)
2h
12 / 64
Example - central finite difference for f (x) = sin(x)
1
f (x) = sin(x) f 0 (x) = cos(x) ∂h = f (x + h) − f (x − h)
2h
h2 Eh
1.0966 0.5865
0.3263 0.2827
0.0895 0.0746
0.0152 0.0123
0.0039 0.0031
13 / 64
Approximation of the second-order derivative
1
∂h2 f (x) := f (x + h) − 2f (x) + f (x − h)
h 2
Suppose that the function f is C4 in the vicinity of x. By subtracting the two expressions
1 f (4) (ξ) 2
f (x + h) − 2f (x) + f (x − h) = f 00 (x) + h , ξ ∈ (x − h, x + h).
h2 12
Hence, we have the following bound on the approximation error:
|f (4) (y)|
1
Eh := 2 f (x + h) − 2f (x) + f (x − h) − f 00 (x) ≤ Ch2 , with C =
sup
h y∈(x−h,x+h) 12
14 / 64
Example - second-order FD for f (x) = sin(x)
1
f (x) = sin(x) f 00 (x) = − sin(x) ∂h2 = f (x + h) − 2f (x) + f (x − h)
h 2
15 / 64
Example - second-order FD for f (x) = sin(x)
1
f (x) = sin(x) f 00 (x) = − sin(x) ∂h2 = f (x + h) − 2f (x) + f (x − h)
h2
h2 Eh
1.0966 0.4053
0.3263 0.0394
0.0895 0.0090
0.0152 0.0014
0.0039 0.0003
16 / 64
NUMERICAL RESOLUTION OF
ODE
Numerical resolution of ODE
Theorem
18 / 64
Numerical resolution of ODE
19 / 64
Forward Euler method
y 0 = y0
yk+1 = yk + (tk+1 − tk )f (yk ), for all k ∈ {0, . . . , N − 1}
The method is explicit because to compute yk+1 I only need information about yk .
20 / 64
Backward Euler method
y0 = y0
yk+1 = yk + (tk+1 − tk )f (yk+1 ), for all k ∈ {0, . . . , N − 1}
The method is implicit because to compute yk+1 I need information about yk+1 itself.
21 / 64
Stability analysis
Two concepts of stability:
Test problem
(
y0 (t) = λy(t) t ∈ (0, T), λ ∈ R
(2)
y(0) = y0
y 0 = y0
yk+1 = yk + hf (yk ) = yk + hλyk = (1 + hλ)yk ⇒ yk = (1 + hλ)k y0 .
In order to ensure stability, we then need that |1 + hλ| < 1. For real λ < 0 this is
equivalent to
2
−2 < hλ < 0 ⇒ h<− .
λ
Conditional stability
The forward Euler method is conditionally stable, i.e., the step size has to
be chosen sufficiently small to ensure stability.
23 / 64
Stability analysis - backward Euler
y0 = y0
k
1 1
yk+1 = yk + hλyk+1 ⇒ yk+1 = yk ⇒ yk = y0 .
1 − hλ 1 − hλ
In order to ensure stability, we then need that |1 − hλ|−1 < 1 ⇒ |1 − hλ| > 1. For real
λ < 0 this is equivalent to
hλ < 0 or hλ > 2.
Conditional stability
24 / 64
Numerical example - forward Euler
Consider (2) with y0 = 0.5, T = 0.5 and λ = −200. We approximate the solution
with the forward Euler method on two meshes of size
• h1 = 2 · 10−2 > − λ2 • h2 = 10−3 < − λ2
On the coarser mesh, the method is unstable and fails in approximating the
real solution of the ODE.
25 / 64
Numerical example - backward Euler
Consider (2) with y0 = 0.5, T = 0.5 and λ = −200. We approximate the solution
with the backward Euler method on two meshes of size
• h1 = 2 · 10−2 > − λ2 • h2 = 10−3 < − λ2
On both meshes, the method is stable and correctly approximates the real
solution of the ODE.
26 / 64
NUMERICAL RESOLUTION OF
PDE: THE FINITE DIFFERENCE
METHOD
The Poisson equation
(
−u00 (x) + u(x) = f (x), x ∈ (a, b)
(3)
u(a) = α ∈ R, u(b) = β ∈ R
Theorem (Schauder)
H. Brezis, Functional analysis, Sobolev spaces and Partial Differential Equations, Springer, 2010.
28 / 64
Finite difference approximation
• N ∈ N.
• xj = a + jh
• h = (b − a)/(N + 1)
• u(x0 ) = α and u(xN+1 ) = β.
• uj := u(xj ) for j ∈ {0, . . . , N + 1}.
• u = (u1 , . . . , uN ) ∈ RN unknown vector.
29 / 64
Finite difference approximation - matrix form
Matrix form
−2 ··· ···
1 0 0
f (x1 ) − hα2
1 −2 1 0 ··· 0
−2 f (x2 )
1 0 1 1 0 0
Ah = 2 f=
.. .. .. .. .. ..
h . . . . .
.
β
0 ··· 0 1 −2 1 f (xN ) − h2
0 ··· ··· 0 1 −2
30 / 64
Existence and uniqueness of solutions
Proposition
31 / 64
Example
( 2
−u00 (x) + u(x) = (1 + 4π 2 ) sin(2πx) + (1 + 4x 2 )ex + e, x ∈ (−1, 1)
u(−1) = u(1) = 0
2
SOLUTION: u(x) = sin(2πx) − ex + e.
32 / 64
Two-dimensional problems
(
−∆u(x) + u(x) = f (x), x ∈ Ω
(5)
u=0 x ∈ ∂Ω
The finite difference method allows approximating the solution of (5) in simple ge-
ometries for the domain Ω (for instance, Ω = [a, b]2 ).
33 / 64
Finite difference approximation
• N ∈ N.
• xj = yj = a + jh
• h = (b − a)/(N + 1)
• uj := u(xj , yj ) for j ∈ {0, . . . , N + 1}.
• uj = (ui, j )N N
i=1 ∈ R for all j ∈ {1, . . . , N}.
2
• U = (uj )N N
j=1 ∈ R .
34 / 64
Finite difference approximation
35 / 64
Finite difference approximation - matrix form
Matrix form
(Ah + I)U = F
| {z }
AFD
P I ··· ···
0 0
I P I ··· f1
0 0
I P I f2
1 0 0 0
Ah = 2 . F= .
.. .. ..
h .. . . . ..
0 ··· 0 I P I fN
0 ··· ··· 0 I P
−4 ··· ···
1 0 0
1 −4 1 0 ··· 0
−4
0 1 1 0 0
P= .
.. .. ..
.. . . .
0 ··· 0 1 −4 1
0 ··· ··· 0 1 −4
36 / 64
Example
2 2 2 2 2
−∆u(x, y) + u(x, y) = (1 − x )(1 − y ) + 2(2 − x − y ), x ∈ (−1, 1)
u(x, −1) = u(x, 1) = 0 x ∈ (−1, 1)
u(−1, y) = u(1, y) = 0 y ∈ (−1, 1)
37 / 64
NUMERICAL RESOLUTION OF
PDE: THE FINITE ELEMENT
METHOD
The Poisson equation
(
−∆u(x) + u(x) = f (x), x ∈ Ω
(6)
u=0 x ∈ ∂Ω
Theorem
If Ω ∈ C1 and f ∈ H−1 (Ω), there exists a unique weak solution u ∈ H10 (Ω) of
(6), characterized through the variational formulation
Z Z Z
∇u(x) · ∇v(x) dx + u(x)v(x) dx = f (x)v(x) dx , for all v ∈ H10 (Ω).
Ω Ω Ω
| {z } | {z }
bilinear form a(u,v) linear functional F(v)
(7)
39 / 64
The finite element method
INGREDIENTS:
40 / 64
The mesh
SN
Let M = {Ti }N
i=1 be a partition of the domain Ω (i.e. Ω = i=1 Ti )
41 / 64
The mesh
SN
Let M = {Ti }N
i=1 be a partition of the domain Ω (i.e. Ω = i=1 Ti )
Moreover, we require that the triangulation satisfies the regularity and local
uniformity conditions:
there exists σ > 0 s.t. hi ≤ σρi for all i = 1, . . . , N ,
there exists κ > 0 s.t. hi ≤ κhj for all i, j = 1, . . . , N , Ti ∩ Tj = ∅.
42 / 64
The finite dimensional space
n o
Vh := v ∈ H10 (Ω) : v |T ∈ P r ,
i
43 / 64
The basis functions - p = 1
n o
• Dimension N = 1: P 1 = φ(x) = a + bx, with a, b ∈ R .
n o
• Dimension N = 2: P 1 = φ(x, y) = a + bx + cy, with a, b, c ∈ R .
44 / 64
The method
STEP 1: by decomposing
N
X N
X Z
u(x) = uj φj (x), f (x) = fj φj (x), fj = f (x)φj (x) dx
j=1 j=1 Ω
45 / 64
The method
Remark
By construction, the basis functions {φi }N i=1 are such that supp(φi ) ∩
supp(φj ) 6= ∅ if and only if j ∈ {i − 1, i, i + 1}. Consequently, the stiffness and
mass matrices are both tri-diagonal.
46 / 64
Finite Element VS Finite Difference
Due to the success that FE methods have had since their introduction, many
computational tools for the FE approximation of PDE have been developed
and perfected in the last decades.
2 2 2 2 2
−∆u(x, y) + u(x, y) = (1 − x )(1 − y ) + 2(2 − x − y ), x ∈ (−1, 1)
u(x, −1) = u(x, 1) = 0 x ∈ (−1, 1)
u(−1, y) = u(1, y) = 0 y ∈ (−1, 1)
48 / 64
Free FEM code
// Mesh
real x0 = -1, x1 = 1, y0 = -1, y1 = 1; // Vertices of the square
int M = 30; // Number of partition points
//for each edge
mesh Th = square(M,M,[x0+(x1-x0)*x,y0+(y1-y0)*y]);
// Save
Vh Ex, Ey;
Ex = -dx(u);
Ey = -dy(u);
savemesh(Th, "Th_circle_mesh.msh");
ffSaveVh(Th,Vh,"Poisson_vh.txt");
ffSaveData3(u,Ex,Ey,"solutionPoisson.txt");
49 / 64
Free FEM code
In Free FEM, we can easily change the geometry of our domain
// Mesh
real a = 2; //The length of the semimajor axis
real b = 1; //The length of the semiminor axis
border Gamma(t=0., 2*pi){x=a*cos(t); y=b*sin(t);}
mesh Th = buildmesh(Gamma(100));
...
// Define and solve the PDE
solve Poisson(u,v) = int2d(Th)(dx(u)*dx(v) + dy(u)*dy(v) + u*v) // Bilinear form
- int2d(Th)(f*v) // Right-hand side
+ on(Gamma,u=0); // Boundary condition
50 / 64
Free FEM
(
x = 2 cos(t) + cos(2t)
POISSON EQUATION ON A DELTOID:
y = 2 sin(t) − sin(2t)
51 / 64
Free FEM
(
x = 3 cos(t) − cos(3t)
POISSON EQUATION ON A NEFROID:
y = 4 sin3 (t)
52 / 64
Free FEM
53 / 64
TIME-DEPENDENT PDE
Time-dependent PDE
ut (x, t) − Au(x, t) = f (x, t) (x, t) ∈ Ω × (0, T)
u(x, t) = 0 (x, t) ∈ ∂Ω × (0, T)
u(x, 0) = u0 (x) x∈Ω
55 / 64
Time-dependent PDE
u(t) = ui (t) N
i=1
ui (t) = u(xi , t)
ut (t) − Ah u(t) = f(t), t ∈ (0, T)
u0 = u0,i N
u0,i = u0 (xi )
u(0) = u0 i=1
f(t) = fi (t) N
i=1
fi (t) = f (xi , t)
BACKWARD EULER:
N M
uj = uij i=1
uij = u(xi , tj )
( j=1
j+1
1
∆t u − u j − Ah u j+1 = f j+1 u0 = u0,i i=1
N
u0,i = u0 (xi )
u0 = u0 M
fj = fi j N
i=1
fi j = f (xi , tj )
j=1
56 / 64
Time-dependent PDE
u(t) = ui (t) N
i=1
ui (t) = u(xi , t)
Mh ut (t) − Ah u(t) = Mh f(t), t ∈ (0, T)
u0 = u0,i N
u0,i = u0 (xi )
u(0) = u0 i=1
f(t) = fi (t) N
i=1
fi (t) = f (xi , t)
BACKWARD EULER:
N M
uj = uij i=1
uij = u(xi , tj )
( j=1
j+1
1
∆t Mh u − u j − Ah u j+1 = Mh f j+1 u0 = u0,i i=1
N
u0,i = u0 (xi )
u0 = u0 M
fj = fi j N
i=1
fi j = f (xi , tj )
j=1
57 / 64
Matrix form
FINITE DIFFERENCE + FORWARD EULER: u j+1 = I + ∆t Ah u j + ∆t f j
−1
FINITE DIFFERENCE + BACKWARD EULER: u j+1 = I − ∆t Ah u j + ∆t f j
FINITE ELEMENT + FORWARD EULER: u j+1 = I + ∆t M−1
h
Ah u j + ∆ t f j
−1
FINITE ELEMENT + BACKWARD EULER: u j+1 = I − ∆t M−1
h
Ah u j + ∆t f j
WARNING
58 / 64
The CFL condition
ut (x, t) − uxx (x, t) = 0 (x, t) ∈ (−1, 1) × (0, T)
u(0, t) = u(1, t) = 0 t ∈ (0, T)
u(x, 0) = u0 (x) x ∈ (0, 1)
1
FINITE DIFFERENCE APPROXIMATION OF −∆: Ah = (∆x )2
tridiag 1, −2, 1
∆t = µ(∆x )2 , µ ∈ (0, 1)
60 / 64
Numerical examples - FD + forward Euler
61 / 64
REFERENCES
References
63 / 64
THANK YOU FOR YOUR ATTENTION!
Funding
64 / 64