Upload
vodiep
View
225
Download
0
Embed Size (px)
Citation preview
236861 Numerical Geometry of Images
Tutorial 2
Introduction to numerical schemes
Lorina Dascal
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
Heat equation
The simple parabolic PDE
∂u
∂t= K
∂2u
∂2x
with the initial values
u(0, x) = u0(x)
and some boundary conditions is called the (one-dimensional) heatequation.
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
I This equation describes the thermal energy transport in a 1Drod, where u(t, x) describes the temperature at a point x attime t and K denotes the thermal conductivity constant.
I In 2D it describes the effect of defocusing on an image inoptics
I The solution is given by convolution of the initial data with aGaussian kernel:
u(x , t) = G (x , t) ∗ u0(x) =
∫
RG (x̄ , t)u0(x − x̄)dx̄
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
Boundary conditions
Dirichlet:
u(t, 0) = a u(t, 1) = b
Neumann:
ux(t, 0) = a ux(t, 1) = b
Mixed boundary conditions:
u(t, 0) = a, ux(t, 1) = b.
Periodic:
u(t, 0−) = u(t, 1+)
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
Discretization of the heat equation
Replace the continuous system of coordinates (t, x) by a discretegrid (n, m) = (n∆t,m∆x), and the continuous function u(t, x) bya discrete version un
m = u(n∆t, m∆x).
Figure: The grid
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
Finite differences
1. Replace the first-order time derivative ut(t, x) by a forwardfinite difference in time
D+t un
m =un+1m − un
m
∆t≈ ut(t).
2. Replace the second-order space derivative uxx(t, x) by acentral difference in space
D0xxu
nm =
unm+1 − 2un
m + unm−1
(∆x)2≈ uxx(x).
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
Finite differences’ motivation
From the Taylor expansion,
u(t + ∆t) = u(t) + ut(t)∆t +1
2utt(t)(∆t)2 + ...
we obtain
ut(t) =u(t + ∆t)− u(t)
∆t− 1
2utt(t)∆t + ...
=u(t + ∆t)− u(t)
∆t+ O(∆t).
This first-order approximation of the first-order derivative is calledthe forward finite-difference approximation and is denoted byD+
t unm.
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
Finite differences
Forward difference
D+t un
m =un+1m − un
m
∆t≈ ut(t) + O(∆t).
In the same manner, backward difference can be defined
D−t un
m =unm − un−1
m
∆t≈ ut(t) + O(∆t).
To approximate a second-order derivative, use the centraldifference approximation
D0xxu
nm =
unm+1 − 2un
m + unm−1
(∆x)2≈ uxx(x) + O((∆x)2).
D0xxu
nm = D−
x D+x un
m.
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
The discrete heat equation
The continuous equation ut(t, x) = Kuxx(t, x) is replaced by
un+1m − un
m
∆t=
unm+1 − 2un
m + unm−1
(∆x)2
or
un+1m = un
m +∆t
(∆x)2K
(unm+1 − 2un
m + unm−1
),
This scheme is explicit (called also Euler scheme) and very simpleto implement.
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
I We denote the continuous solution by U = u(t, x) and thediscrete solution by u = un
m.
I We denote the continuous PDE operator L = ∂t − K∂xx .
I We denote the discrete operator L∆t,∆x = D+t − KD0
xx .
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
Stability and Convergence
1. Convergence: the discrete solution converges to thecontinuous solution
lim∆t,∆x→0
‖u − U‖ .
in certain norm.
2. Consistency: the discrete difference operator solutionconverges to the continuous solution
lim∆t,∆x→0
‖L(u)− L∆t,∆x(u) ‖ = 0
for every bounded u.
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
Stability
3. Numerical stability: noise from initial conditions, numericalerrors, etc. is not amplified.The numerical scheme is un+1 = Nun
Formally, stability means
∀N > 0 ∃C (N) > 0 s.t. ∀n ≤ N ‖N n‖ ≤ C (N).
Lax’s equivalence theorem: Given a properly posed initial valueproblem and a finite-difference approximation to it that satisfiesthe consistency condition, stability is the necessary and sufficientcondition for convergence.
consistency + stability ⇔ convergence
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
0 10 20 30 40 50 60 70−8
−6
−4
−2
0
2
4
6
8Initial data
0 10 20 30 40 50 60 70−5
−4
−3
−2
−1
0
1
2
3
4
5 Solution to 1−D heat equation
dt=0.0008
0 10 20 30 40 50 60 70−5
−4
−3
−2
−1
0
1
2
3
4
5Solurion to 1−D heat eq
dt=0.004
0 10 20 30 40 50 60 70−4
−3
−2
−1
0
1
2
3
4x 10
70
dt=0.006
Figure: Computation of the discrete heat equation with Neumannboundary conditions. (h = 0.1) Top left: Initial data. Top right: stablesolution of the heat equation conditions ∆t = 0.0008. Bottom left:stable solution of the heat equation for ∆t = 0.004. Bottom right:unstable solution (∆t = 0.006).
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
CFL condition for stability of the discrete heat equation
Denote r = K ∆t(∆x)2
. The finite difference scheme is
un+1m = un
m + r(unm+1 − 2un
m + unm−1
)
= (1− 2r)unm + run
m+1 + runm−1
If 1− 2r > 0, we can write:
un+1m ≤ (1− 2r)max
munm + r max
munm + r max
munm
Then un+1m ≤ max
munm(1− 2r + 2r) = max
munm.
(maximum principle property)
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
Observation: Maximum principle implies stability of the scheme.
Lemma(Maximum principle)If K ∆t
(∆x)2≤ 1/2, then
minm
u0m ≤ un
m ≤ maxm
u0m.
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
Implicit finite difference schemes for the heat equation
un+1m − un
m
∆t= K
un+1m+1 − 2un+1
m + un+1m−1
(∆x)2
I Main advantage of implicit schemes: are unconditionallystable (i.e. stable for all time-steps and thus we can take largestep times).(I −∆tA)Un+1 = Un.
I Requires solving a linear system of equations. The matrix(I −∆tA) is tridiagonal and can to be inverted using theThomas algorithm (we will describe it in detail in a futuretutorial).
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
The 2D heat equation. Numerical scheme.
ut = K (uxx + uyy )
un+1m,p = un
m,p + K( ∆t
(∆x)2(un
m+1,p − 2unm,p + un
m−1,p)+
+∆t
(∆y)2(un
m,p+1 − 2unm,p + un
m,p−1)).
The CFL condition:
K( ∆t
(∆x)2+
∆t
(∆y)2
)≤ 1
2.
If ∆x = ∆y , then the CFL condition is:
K∆t
(∆x)2≤ 1
4.
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes
The 2D heat equation. Numerical example
Figure: Application of the heat eq. on a gray-scale image.
Lorina Dascal CS 236861 - Tutorial 2 - Introduction to numerical schemes