Fem
Fem
Fem
Mohammad Asadzadeh
1 Introduction 1
1.1 Ordinary differential equations (ODE) . . . . . . . . . . . . . 1
1.2 Partial differential equations (PDE) . . . . . . . . . . . . . . . 2
1.2.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2 Polynomial Approximation in 1d 9
2.1 Overture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1.1 Basis function in nonuniform partition . . . . . . . . . 14
2.2 Variational formulation for (IVP) . . . . . . . . . . . . . . . . 17
2.3 Galerkin finite element method for (2.1.1) . . . . . . . . . . . 19
2.4 A Galerkin method for (BVP) . . . . . . . . . . . . . . . . . . 21
2.4.1 The nonuniform version . . . . . . . . . . . . . . . . . 26
2.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
iii
iv CONTENTS
void
Chapter 1
Introduction
du
− u(t) = 0, (1.0.1)
dt
is an ordinary differetial equation, whereas
∂u ∂ 2 u
− 2 = 0, (1.0.2)
∂t ∂x
2
is a partial differential (PDE) equation. In (1.0.2) ∂u
∂t
, ∂∂xu2 denote the partial
derivatives. Here t denotes the time variable and x is the space variable. We
shall only study one space dimentional equations that are either stationary
(time-independent) or time dependent. Our focus will be on the following
equations:
du
− λu(t) = f (t), (1.1.1)
dt
1
2 CHAPTER 1. INTRODUCTION
Solution. Since u(t) 6= 0, for all t, we may divide the equation (1.2.4) by
4 CHAPTER 1. INTRODUCTION
u̇(t)
u(t) and get u(t)
= λ. Relabeling t by s and integrating over (0, t) we get
Z t Z t h it
u̇(s)
ds = λ ds =⇒ ln u(s) = λ[s]t0 . (1.2.5)
0 u(s) 0 0
Hence we have
u(t)
ln u(t) − ln u(0) = λt or ln = λt. (1.2.6)
u(0)
Thus
u(t)
= eλt , i.e. u(t) = u0 eλt . (1.2.7)
u(0)
Consequently, with λ = 1 and u0 = 2 we have u(t) = 2et .
To derive solutions to our examples on a systematic way, we recall the pro-
cedure for determining a particular solution up to a second order differential
equation with constant coefficiets of the form:
u′′ (x) + au′ (x) + bu(x) = f (x). (1.2.8)
i) up (x) = a0 + a1 x + · · · + an xn , if b 6= 0
ii) up (x) = x(a0 + a1 x + · · · + an xn ), if b = 0, a 6= 0
i) up (x) = z(x)eσx .
This gives a new differential equation for z solved by 1).
ii) up (x) = Aeσx , if polynom = constant.
This works if σ 2 + aσ + b 6= 0: i.e. σ is not a root to the
characteristic equation.
Step 3: Finally, the general solution is given by adding the particular and
homogeneous solutions
1
u(x) = − cos x + C1 ex + C2 e−x . (1.2.14)
2
In the above example we obtained general solutions depending on two con-
stants. Below we shall demonstrate an example where, supplying two bound-
ary conditions, we obtain a unique solution
6 CHAPTER 1. INTRODUCTION
Example 1.5. Determine the unique solution of the following boundary value
problem
Homogeneous solution:
The characteristic equation for the differential equation (1.2.15) is given by
Particular solution:
The particula solution can be written as sum of two particular solution to
the following equations:
and
u′′2 + 2u′2 + u2 = 2 sin x. (1.2.19)
Since the differential equation is linear, a concept justified by the relation
u1 (x) = x − 1.
Once again using the table of particular solutions, we may insert u2 (x) =
A sin x + B cos x, as particular solution, in (1.2.19) and get
u2 (x) = − cos x.
1.2. PARTIAL DIFFERENTIAL EQUATIONS (PDE) 7
Now we use the boundary conditions and determine the coefficients C1 and
C2 . Observe that
u(0) = 1 =⇒ C1 − 1 − 1 = 1 =⇒ C1 = 3.
Further
u′ (0) = 0 =⇒ C2 − C1 + 1 = 0 =⇒ C2 = C1 − 1 =⇒ C2 = 2.
1.2.1 Exercises
Problem 1.1. Find all solutions to the following homogeneous (their right
hand side is zero “0”) differential equations
a) u′′ − 3u′ + 2u = 0 b) u′′ + 4u = 0 c) u′′ − 6u′ + 9u = 0
Problem 1.4. Solve the boundary value problem for all x ∈ (0, 1),
Polynomial Approximation in
1d
2.1 Overture
Below we shall introduce a few standard examples of classical differential
equations and some regularity requirements.
Ordinary differential equations (ODEs)
An initial value problem (IVP), for instance a model in population dynamics
where u(t) is the size of the population at time t, can be written as
u̇(t) = λu(t), 0 < t < T, u(0) = u0 , (2.1.1)
where u̇(t) = du
dt
and λ is a positive constant. For u0 > 0 this problem has
the increasing analytic solution u(t) = u0 eλ·t , which blows up as t → ∞.
9
10 CHAPTER 2. POLYNOMIAL APPROXIMATION IN 1D
t0 = 0 t1 t2 t3 tN = T
u(tk+1 ) − u(tk )
= λ · u(tk ), k = 0, . . . , N − 1, and u(0) = u0 , (2.1.2)
tk+1 − tk
Starting with k = 0 and the data u(0) = u0 , the solution u(tk ) would, itera-
tively, be computed at the subsequent points: t1 , t2 , . . . , tN = T .
For a uniform partition, where all subintervals have the same length ∆t,
(2.1.3) would be of the form
Iterating we get
Other finite difference methods for (2.1.1) are introduced in Chapter 5. There
are corresponding finite difference methods for PDE’s. Our goal, however, is
to study the Galerkin finite element method. To this approach we need to
introduce some basic tools:
−1
Subtracting the two relations above we get A(b − a) = −1 =⇒ A = b−a
.
b
Then, from the second relation: B = −Ab we get B = b−a . Thus,
b−x x−a
λa (x) = . Likewise λb (x) = .
b−a b−a
1
λa (x) λb (x)
x
a b
Note that
λa (x) + λb (x) = 1, and aλa (x) + bλb (x) = x.
12 CHAPTER 2. POLYNOMIAL APPROXIMATION IN 1D
Thus, we get the original basis functions: 1 and x for the linear polynomial
functions, as a linear combination of the basis functions λa (x) and λb (x).
Hence, any linear function f (x) on an interval [a, b] can be written as:
This is easily seen by the fact that the right hand side in (2.1.5) yields:
Example 2.3. Let [a, b] = [0, 1] then λ0 (x) = 1 − x and λ1 (x) = x. Consider
the linear function f (x) = 3x + 5/2. Then f (0) = 5/2, f (1) = 11/2 and
5 11
f (0)λ0 (x) + f (1)λ1 (x) = (1 − x) + x = 3x + 5/2 = f (x).
2 2
Definition 2.1. Let f (x) be a real valued function definied on R or on an
interval that contains [a, b]. A linear interpolant of f (x) on a and b is a
linear function π1 f (x) such that π1 f (a) = f (a) and π1 f (b) = f (b).
b−x x−a
π1 f (x) = f (a) + f (b) .
b−a b−a
Below, for simplicity, first we shall assume a uniform partition of the interval
[0, 1] into M + 1 subintervals of the same size h, i.e., we let xj = jh, and
consider subintervals Ij := [xj−1 , xj ] = [(j − 1)h, jh] for j = 1, . . . , M + 1.
Then setting a = xj−1 = (j − 1)h and b = xj = jh we may define
x − jh x − (j − 1)h
λj−1 (x) = − and λj (x) = .
h h
We denote the space of all continuous piecewise linear polynomial func-
tions on Th , by Vh . Let
π1 f (x)
f (x)
x
a b
x
x0 x1 x2 xj−1 xj xM xM +1 = 1
h h h
Figure 2.3: An example of a function in Vh0 with uniform partition.
1
ϕj (x)
x
x0 x1 x2 xj−1 xj xM xM +1 = 1
h2 hj hM +1
1
ϕj (x)
Vector spaces
To establish a framework we introduce some basic mathematical concepts:
Definition 2.2. A set V of functions or vectors is called a linear space, or
a vector space, if for all u, v ∈ V and all α ∈ R (real number), we have that
(i) u + v ∈ V, (closed under addition)
(ii) αu ∈ V, (closed under multiplication by scalars), (2.1.6)
(iii) ∃ (−u) ∈ V : u + (−u) = 0, (closed under inverse),
where (i) and (ii) obey the usual rules of addition and multiplication by
scalars. Observe that α = 0 in (ii) (or (iii) and (i), with v = (−u)), implies
that 0 (zero vector) is an element of every vector space.
16 CHAPTER 2. POLYNOMIAL APPROXIMATION IN 1D
Here are examples of some vector spaces that are also linear product
spaces associated with the scalar product defined by (2.1.8).
• C(a, b): The space of continuous functions on an interval (a, b),
• P (q) [a, b]: the space of all polynomials of degree ≤ q on C[a, b] and
• Vh (a, d) and Vh0 (a, b) defined above.
The reader may easily check that all the properties (i) − (iv), in the
definition, for the scalar product are fullfiled for these spaces.
Definition 2.5. Two (real-valued) functions u(x) and v(x) are called orthog-
onal if hu, vi = 0. The orthogonality is also denoted by u ⊥ v.
Example 2.5. For the functions u(x) = 1 and v(x) = x, we have that
Z 1 Z 1 Z 1 Z 1
u(x)v(x)dx = 1×x dx = 0, u(x)v(x)dx = 1×x dx = 1/2 6= 0.
−1 −1 0 0
Thus, 1 and x are orthogonal on the interval [−1, 1], but not on [0, 1].
Definition 2.6 (Norm). If u ∈ V then the norm of u, or the length of u,
associated with the scalar product (2.1.8) above is defined by:
p Z b 1/2
1/2
kuk = hu, ui = hu, ui = |u(x)|2 dx . (2.1.9)
a
This norm is known as the L2 -norm of u(x). There are other norms that we
will introduce later on.
2.2. VARIATIONAL FORMULATION FOR (IVP) 17
Now we recall one of the most useful inequalities that is frequently used in
estimating the integrals of product of two functions.
Lemma 2.1 (The Cauchy-Schwarz inequality). For all inner products with
their corresponding norms We have that
Then by the definition of the L2 -norm and the symmetry property of the
scalar product we get
or equivalently
Z T
(u̇(t) − λ u(t))v(t)dt = 0, ∀v(t) ∈ V, (2.2.2)
0
We look for an approximate solution U (t), called a trial function for (2.1.1),
in the space of polynomials of degree ≤ q:
Moving the data to the right hand side, this relation can be rewritten as
Z 1X q Z 1
i+j−1 i+j
(jξj t − λ ξj t ) dt = λu0 ti dt, i = 1, 2, . . . , q. (2.3.3)
0 j=1 0
or equivalently
q
X j λ λ
− ξj = · u0 i = 1, 2, . . . , q, (2.3.5)
j=1
i + j i + j + 1 i + 1
j λ
from aij = − , are very close to each other resulting in a very
i+j i+j+1
small value for the determinant of A.
If we insist to use polynomial basis up to certain order, then instead of
monomials, the use of Legendre orthogonal polynomials would yield a diago-
nal (sparse) coefficient matrix and make the problem well conditioned. This
however, is a rather tedious task. A better approach would be through the
use of piecewise polynomial approximations (see Chapter 5) on a partition of
[0, T ] into subintervals, where we use low order polynomial approximations
on each subinterval.
The L2 -projection onto a space of polynomials
A polynomial πf interpolating a given function f (x) on an interval (a, b)
agrees with point values of f at a certain discrete set of points xi ∈ (a, b) :
πf (xi ) = f (xi ), i = 1, . . . , n, for some integer n. This concept can be gener-
alized to determine a polynomial P f so that certain averages agree. These
could include the usual average of f over [a, b] defined by,
Z b
1
f (x) dx,
b−a a
Pf
x
x0 x1 x2 xM xM +1 = 1
Let Th : {jh}M +1
j=0 , (M + 1)h = 1 be a uniform partition of the interval [0, 1]
into the subintervals Ij = ((j − 1)h, jh), with the same length |I| = h,
j = 1, 2, . . . , M + 1. We define the finite dimensional space Vh0 by
with the basis functions {ϕj }Mj=1 defined below (these functions will be used to
determine the values of approximate solution at the points xj , j = 1, . . . , M.
Due to the fact that u is known at the boundary points 0 and 1; it is not
necessary to supply test functions corresponding to the values at x0 = 0 and
xM +1 = 1. However, in the case of given non-homogeneous boundary data
u(0) = u0 6= 0 and/or u(1) = u1 6= 0, to represent the trial function, one uses
the basis functions to all internal nodes as well as those corresponding to the
non-homogeneous data (i.e. at x = 0 and/or x = 1).
Remark 2.1. If the Dirichlet boundary condition is given at only one of the
boundary points; say x0 = 0 and the other one satisfies, e.g. a Neumann
condition as
ϕ1 ϕj ϕM ϕM +1
x
x0 x1 x2 xj−1 xj xj+1 xM −1 xM xM +1
h h
Thus the variational formulation for (2.4.1) is: Find u ∈ V0 such that
Z 1 Z 1
′ ′
u (x)v (x) dx = f (x)v(x)dx, ∀v ∈ V0 (2.4.6)
0 0
The Galerkin finite element method (FEM) for the problem (2.4.1):
Find U (x) ∈ Vh0 such that
Z 1 Z 1
′ ′
U (x)v (x) dx = f (x)v(x)dx, ∀v(x) ∈ Vh0 . (2.4.7)
0 0
Since every v(x) ∈ Vh0 is a linear combination of the basis functions ϕi (x),
it suffices to try with v(x) = ϕi (x), for i = 1, 2, . . . , M : That is, to find ξj
(constants), 1 ≤ j ≤ M such that
M Z
X 1 Z 1
ϕ′i (x)ϕ′j (x)dx ξj = f (x)ϕi (x)dx, i = 1, 2, . . . , M. (2.4.10)
j=1 0 0
To compute the entries aij of the matrix A, first we need to derive ϕ′i (x), viz
x−(i−1)h
(i − 1)h ≤ x ≤ ih
h
(i+1)h−x
ϕi (x) = ih ≤ x ≤ (i + 1)h
h
0 else
1
(i − 1)h < x < ih
h
Stiffness matrix A:
If |i − j| > 1, then ϕi and ϕj have disjoint support, see Figure 2.7, and
Z 1
aij = ϕ′i (x)ϕ′j (x)dx = 0.
0
1
ϕj−1 ϕj+1
x
xj−2 xj−1 xj xj+1 xj+2
h h
Z 1 2 Z z }| { z }| {
xi xi+1
1 2 xi − xi−1 xi+1 − xi 1 1 2
aii = dx + − dx = + = + = .
xi−1 h xi h h2 h2 h h h
2.4. A GALERKIN METHOD FOR (BVP) 25
1
ϕj ϕj+1
x
xj−1 xj xj+1 xj+2
a = 0, if |i − j| > 1,
ij
aii = h2 , i = 1, 2, . . . , M, (2.4.15)
a 1
i−1,i = ai,i−1 = − h , i = 2, 3, . . . , M.
By symmetry aij = aji , and we finally have the stiffness matrix for approxi-
mating the stationary heat conduction by piecewise linear polynomials in a
uniform mesh, as:
2 −1 0 . . . . . . 0
−1 2 −1 0 . . . . . .
1
0 −1 2 −1 0 . . .
.
Aunif = · (2.4.16)
h ... ... ... ... ... 0
. . . . . . 0 −1 2 −1
0 . . . . . . 0 −1 2
26 CHAPTER 2. POLYNOMIAL APPROXIMATION IN 1D
with the nonuniform basis functions {ϕj }M j=1 . To compute the entries aij of
the coefficient matrix A, first we need to derive ϕ′i (x) for the nonuniform
basis functions: i.e.,
x−xi−1
xi−1 ≤ x ≤ xi
hi
xi+1 −x
ϕi (x) = xi ≤ x ≤ xi+1 =⇒
hi+1
0 else
1
xi−1 < x < xi
hi
ϕ′i (x) = 1
− hi+1 xi < x < xi+1
0 else
Nonuniform stiffness matrix A:
If |i − j| > 1, then ϕi and ϕj have disjoint support, see Figure 2.9, and
Z 1
aij = ϕ′i (x)ϕ′j (x)dx = 0.
0
By symmetry aij = aji , and we finally have the stiffness matrix in nonuniform
mesh, for the stationary heat conduction as:
1 1 1
+ − h2 0 ... 0
h1 h2
1 1 1 1
− h2 + h 3 − h3 0 0
h 2
A= 0 ... ... ... 0 . (2.4.19)
... 0 ... ... − h1M
0 ... 0 − h1M h1M + hM1+1
2.5 Exercises
(q)
Problem 2.1. Prove that V0 := {v ∈ P (q) (0, 1) : v(0) = 0}, is a subspace
of P (q) (0, 1).
Problem 2.2. Consider the ODE: u̇(t) = u(t), 0 < t < 1; u(0) = 1.
(q)
Compute its Galerkin approximation in P (0, 1), for q = 1, 2, 3, and 4.
28 CHAPTER 2. POLYNOMIAL APPROXIMATION IN 1D
Problem 2.3. Consider the ODE: u̇(t) = u(t), 0 < t < 1; u(0) = 1.
3
Compute the L2 (0, 1) projection of the exact solution u into P (0, 1).
Problem 2.4. Compute the stiffness matrix and load vector in a finite ele-
ment approximation of the boundary value problem
Problem 2.8. Use the projection technique of the previous exercises to solve
Interpolation, Numerical
Integration in 1d
3.1 Preliminaries
Definition 3.1. A polynomial interpolant πq f of a function f , defined on
an interval I = [a, b], is a polynomial of degree ≤ q having the nodal values
at q + 1 distinct points xj ∈ [a, b], j = 0, 1, . . . , q, coinciding with those of f ,
i.e., πq f ∈ P q (a, b) and πq f (xj ) = f (xj ), j = 0, . . . , q.
Below we illustrate this definition through a simple and familiar example.
31
32CHAPTER 3. INTERPOLATION, NUMERICAL INTEGRATION IN 1D
then )
x=0 =⇒ α0 = 0
=⇒ α0 = α1 = 0. (3.1.4)
x=1 =⇒ α1 = 0
f (x) λ0 (x) = 1 − x
1
π1 f (x) λ1 (x) = x
1 1
Lp (a, b)-norm: Assume that f is a real valued function defined on the in-
terval (a, b). Then we define the Lp -norm (1 ≤ p ≤ ∞) of f by
Z b 1/p
p
Lp -norm kf kLp (a,b) := |f (x)| dx , 1 ≤ p < ∞,
a
L∞ -norm kf kL∞ (a,b) := max |f (x)|.
x∈[a,b]
Proof. Note that every linear function, p(x) on [a, b] can be written as a
linear combination of the basis functions λa (x) and λb (x) where
b−x x−a
λa (x) = and λb (x) = : (3.1.6)
b−a b−a
p(x) = p(a)λa (x) + p(b)λb (x). (3.1.7)
Recall that linear combinations of λa (x) and λb (x) give the basis functions
{1, x} for P 1 :
Here, π1 f (x) being a linear function connecting the two points (a, f (a)) and
(b, f (b)), is represented by
x
a b a b
By the Taylor expansion for f (a) and f (b) about x ∈ (a, b) we can write
1
f (a) = f (x) + (a − x)f ′ (x) + (a − x)2 f ′′ (ηa ), ηa ∈ [a, x]
2 (3.1.10)
1
f (b) = f (x) + (b − x)f (x) + (b − x)2 f ′′ (ηb ), ηb ∈ [x, b].
′
2
3.1. PRELIMINARIES 35
Inserting f (a) and f (b) from (3.1.10) into (3.1.9), it follows that
1
π1 f (x) =[f (x) + (a − x)f ′ (x) + (a − x)2 f ′′ (ηa )]λa (x)+
2
1
+[f (x) + (b − x)f (x) + (b − x)2 f ′′ (ηb )]λb (x).
′
2
Rearranging the terms, using (3.1.8) and the identity (which also follows
from (3.1.8)) (a − x)λa (x) + (b − x)λb (x) = 0 we get
1 1
|π1 f (x)−f (x)| ≤ (a−b)2 ·1·kf ′′ kL∞ (a,b) + (a−b)2 ·1·kf ′′ kL∞ (a,b) , (3.1.12)
2 2
and hence
The other two estimates (2) and (3) are proved similarly.
Remark 3.2. We can show that the optimal value of C1 = 18 (cf Problem
3.10), i.e. the constant C1 = 1 of the proof above is not the optimal one.
Theorem 3.2. Let π1 v(x) be the linear interpolant of the function v(x) on
(a, b). Then, assuming that v is twice differentiable (v ∈ C 2 (a, b)), there are
interpolation constants ci , i = 1, 2, 3 such that for p = 1, 2, ∞,
kπ1 v − vkLp (a,b) ≤ c1 (b − a)2 kv ′′ kLp (a,b) , (3.1.14)
k(π1 v)′ − v ′ kLp (a,b) ≤ c2 (b − a)kv ′′ kLp (a,b) , (3.1.15)
kπ1 v − vkLp (a,b) ≤ c3 (b − a)kv ′ kLp (a,b) . (3.1.16)
For p = ∞ this is just the previous Theorem 3.1.
Proof. For p = 1 and p = 2, the proof uses the integral form of the Taylor
expansion and is left as an exercise.
Below we review a simple piecewise linear interpolation procedure on a
partition of an interval:
Proof. Both the left and right hand side are continuous piecewise linear func-
tions. Thus it suffices to show that they have the same nodal values: Let
x = xj , then since ϕi (xj ) = δij ,
RHS|xj =v(x0 )ϕ0 (xj ) + v(x1 )ϕ1 (xj ) + . . . + v(xj−1 )ϕj−1 (xj )
+ v(xj )ϕj (xj ) + v(xj+1 )ϕj+1 (xj ) + . . . + v(xN )ϕN (xj ) (3.1.19)
=v(xj ) = LHS|xj .
3.1. PRELIMINARIES 37
Definition 3.4. Assume that f is a continuous function in [a, b]. Then the
continuous piecewise linear interpolant of f is defined by
N
X
πh f (x) = f (xj )ϕj (x), x ∈ [a, b].
j=0
Hence
πh f (xj ) = f (xj ), j = 0, 1, . . . , N. (3.1.20)
Remark 3.3. Note that we denote the linear interpolant, defined for a single
interval [a, b], by π1 f which is a polynomial of degree 1, whereas the piecewise
linear interpolant πh f is defined for a partition Th of [a, b] and is a piecewise
linear function. For the piecewise polynomial interpolants of (higher) degree
q we shall use the notation for Cardinal functions of Lagrange interpolation
(see Section 3.2).
πh f (x) f (x)
x
x0 x1 x2 xj xN −1 xN
xj − x x − xj−1
πh f (x) = c0 + c1 x = f (xj−1 ) + f (xj )
xj − xj−1 xj − xj−1
= f (xj−1 )λj−1 (x) + f (xj )λj (x),
where λj−1 (x) and λj (x) are the restrictions of the piecewise linear basis
functions ϕj−1 (x) and ϕj (x) to Ij .
1
x−xj−1
λj−1 (x) =
xj −x λj (x) = xj −xj−1
xj −xj−1
x
xj−1 xj
In the next section we shall generalize the above procedure and introduce
Lagrange interpolation basis functions.
The main result of this section can be stated as follows:
3.2. LAGRANGE INTERPOLATION 39
Theorem 3.3. Let πh v(x) be the piecewise linear interpolant of the function
v(x) on the partition Th of [a, b]. Then assuming that v is sufficiently regular
(v ∈ C 2 (a, b)), there are interpolation constants ci , i = 1, 2, 3, such that for
p = 1, 2, ∞,
N
X N
X
kπh v − vkpLp (a,b) = kπh v − vkpLp (Ij ) ≤ cp1 kh2j v ′′ kpLp (Ij )
j=1 j=1 (3.1.25)
≤ cp1 kh2 v ′′ kpLp (a,b) ,
(x1 − x0 )(x1 − x2 )
i = j = 1 ⇒ λ1 (x1 ) = = 1.
(x1 − x0 )(x1 − x2 )
A polynomial P (x) ∈ P q (a, b) with the values pi = P (xi ) at the nodes xi ,
i = 0, 1, . . . , q, can be expressed in terms of the above Lagrange basis as
P (x) = p0 λ0 (x) + p1 λ1 (x) + . . . + pq λq (x). (3.2.3)
Using (3.2.2), P (xi ) = p0 λ0 (xi )+p1 λ1 (xi )+. . .+pi λi (xi )+. . .+pq λq (xi ) = pi .
Recalling definition 3.1, if we choose a ≤ ξ0 < ξ1 < . . . < ξq ≤ b, as
q + 1 distinct interpolation nodes on [a, b], then the interpolating polynomial
πq f ∈ P q (a, b) satisfies
πq f (ξi ) = f (ξi ), i = 0, 1, . . . , q (3.2.4)
and the Lagrange formula (3.2.3) for πq f (x) reads as
πq f (x) = f (ξ0 )λ0 (x) + f (ξ1 )λ1 (x) + . . . + f (ξq )λq (x), a ≤ x ≤ b.
Example 3.3. For q = 1, we have only the nodes a and b. Recall that
b−x x−a
λa (x) = and λb (x) = , thus as in the introduction in this chapter
b−a b−a
π1 f (x) = f (a)λa (x) + f (b)λb (x). (3.2.5)
3.3. NUMERICAL INTEGRATION, QUADRATURE RULES 41
f (b)
f (a + h/2) P0 (x)
f (a)
x
a = x0 a + h/2 b = x1
R x1
Figure 3.5: Midpoint approximation I0 of the integral I = x0
f (x)dx.
ii) Simple trapezoidal rule uses the values of f at two endpoints a and b, i.e.
f (a) and f (b). Here f is approximated by the linear function
(polynomial
of degree 1) P1 (x) passing through the two points a, f (a) and b, f (b) .
Consequently, the area under the curve y = f (x) is approximated as
Z b
f (a) + f (b)
I= f (x)dx ≈ (b − a) . (3.3.3)
a 2
written as
h[f (a + h) − f (a)] f (a) + f (a + h)
I ≈ I1 =hf (a) + =h
2 2 (3.3.4)
h
≡ [f (x0 ) + f (x1 )].
2
iii) Simple Simpson’s rule uses the values of f at the two endpoints a and b,
P1 (x) f (b)
f (a)
x
a = x0 b = x1 = a + h
R x1
Figure 3.6: Trapezoidal approximation I1 of the integral I = x0
f (x)dx.
and the midpoint a+b2
of the interval [a, b], i.e. f (a), f (b), and f a+b
2
. In this
case the area under y = f (x) is approximated by the area under the graph of
the second degree polynomial P2 (x); with P2 (a) = f (a), P2 a+b 2
= f a+b
2
,
and P2 (b) = f (b). To determine P2 (x) we may use Lagrange interpolation
for q = 2: let x0 = a, x1 = (a + b)/2 and x2 = b, then
P2 (x) = f (x0 )λ0 (x) + f (x1 )λ1 (x) + f (x2 )λ2 (x), (3.3.5)
where
λ (x) = (x−x1 )(x−x2 )
,
0 (x0 −x1 )(x0 −x2 )
(x−x0 )(x−x2 )
λ1 (x) = , (3.3.6)
(x1 −x0 )(x1 −x2 )
λ (x) = (x−x0 )(x−x1 )
2 (x2 −x0 )(x2 −x1 )
.
Thus
Z b Z b 2
X Z b
I= f (x)dx ≈ P2 (x) dx = f (xi ) λi (x) dx. (3.3.7)
a a i=0 a
44CHAPTER 3. INTERPOLATION, NUMERICAL INTEGRATION IN 1D
f (b)
f (x)
f (a)
P2 (x)
x
a = x0 a + h/2 b = x1
R x1
Figure 3.7: Simpson’s rule approximation I2 of the integral I = x0
f (x)dx.
Obviously these approximations are less accurate for large intervals, [a, b]
and/or oscillatory functions f . Following Riemann’s idea we can use these
rules, instead of on the whole interval [a, b], for the subintervals in an appro-
priate partition of [a, b]. Then we get the following generalized versions.
b−a xk−1 + xk
h = |Ik | = , and x̄k = , k = 1, 2, . . . , N.
N 2
Then, using the simple midpoint rule for the interval Ik := [xk−1 , xk ],
Z xk Z xk
f (x) dx ≈ f (x̄k ) dx = hf (x̄k ). (3.3.12)
xk−1 xk−1
hz
< >
a = z0 z1 z2 z2k−2 z2k−1 z2k z2N = b
Then, summing (3.3.16) over k and using the above identification, we obtain
the composite Simpson’s rule viz,
Z
hh x + xk i
b N
X k−1
f (x)dx ≈ f (xk−1 ) + 4f + f (xk )
a k=1
6 2
hz h i
XN
= f (z2k−2 ) + 4f (z2k−1 ) + f (z2k )
3 (3.3.18)
k=1
hz h
= f (z0 ) + 4f (z1 ) + 2f (z2 ) + 4f (z3 ) + 2f (z4 )
3 i
+ . . . + 2f (z2N −2 ) + 4f (z2N −1 ) + f (z2N ) := SN .
3.3. NUMERICAL INTEGRATION, QUADRATURE RULES 47
The figure below illustrates the starting procedure for the composite Simp-
son’s rule. The numbers in the brackets indicate the actual coefficients on
each subinterval. For instance the end of the first interval: x1 = z2 , coincides
with the start of the second interval, ending to the add-up [1] + [1] = 2 as
the coefficient of f (z2 ). This is the case for each interior node xk , i.e. z2k :s;
k = 1, . . . , N − 1.
[4] [4]
[1] + [1]
[1] [1]
z0 z1 z2 z3 z4
Remark 3.4. One can verify that the errors of these integration rules are
depending on the regularity of the function and the size of interval (in simple
rules) and the mesh size (in the composite rules). These error estimates, for
both simple and composite quadrature rules, can be found in any elementary
text book in numerical linear algebra and/or numerical analysis are read as
follows:
Eroor in simple Midpoint rule
Z xk
h3
| f (x) dx − hf (x̄k )| = |f ′′ (η)|, η ∈ (xk−1 , xk ).
xk−1 24
Remark 3.5. The rules (M), (T) and (S) use values of the function at
equally spaced points. These are not always the best approximation methods.
Below we introduce a general and more optimal approach.
Exercises
b−x x−a
Problem 3.1. Use the expressions λa (x) = b−a
and λb (x) = b−a
to show
λa (x) + λb (x) = 1, and aλa (x) + bλb (x) = x.
50CHAPTER 3. INTERPOLATION, NUMERICAL INTEGRATION IN 1D
a -
x b
Show that Z Z
−1
h |ϕ − v| dx ≤ |ϕ′ | dx. (3.3.25)
I I
Problem 3.6. Show that P q (a, b) = {the set of polynomials of degree ≤ q},
is a vector space but, P q (a, b) := {p(x)|p(x) is a polynomial of degree = q},
is not a vector space.
||f − πh f ||L∞ (a,b) ≤ max hi ||f ′ ||L∞ (Ii ) = ||hf ′ ||L∞ (a,b) .
1≤i≤m+1
Prove that choosing the midpoint improves the bound by an extra factor 1/2.
2
Problem 3.10. Compute and graph π4 e−8x on [−2, 2], which interpolates
2
e−8x at 5 equally spaced points in [−2, 2].
Problem 3.11. Write down a basis for the set of piecewise quadratic poly-
(2)
nomials Wh on a partition a = x0 < x1 < x2 < . . . < xm+1 = b of (a, b)
into subintervals Ii = (xi−1 , xi ), where
(q)
Wh = {v : v|Ii ∈ P q (Ii ), i = 1, . . . , m + 1}.
(2)
Note that, a function v ∈ Wh is not necessarily continuous.
Problem 3.12. Determine a set of basis functions for the space of continuous
(2)
piecewise quadratic functions Vh on I = (a, b), where
(q) (q)
Vh = {v ∈ Wh : v is continuous on I}.
x1 +x0
Hint: Use Taylor expansion of f about x = 2
.
52CHAPTER 3. INTERPOLATION, NUMERICAL INTEGRATION IN 1D
Chapter 4
Equation (4.1.1) is of Poisson’s type modelling also the stationary heat flux.
We shall assume that a(x) is piecewise continuous function in (0, 1),
bounded for 0 ≤ x ≤ 1 and a(x) > 0 for 0 ≤ x ≤ 1.
53
54 CHAPTER 4. TWO-POINT BOUNDARY VALUE PROBLEMS
Let v(x) and its derivative v ′ (x), x ∈ I, be square integrable functions, that
is: v, v ′ ∈ L2 (0, 1), and define the L2 -based Sobolev space by
n Z 1 o
1 2 ′ 2
H0 (0, 1) := v(x) : (v(x) + v (x) )dx < ∞, v(0) = v(1) = 0 . (4.1.2)
0
Now since v(0) = v(1) = 0 we have thus obtained the variational formulation
for the problem (4.1.1) as follows: find u(x) ∈ H01 such that
Z 1 Z 1
(VF) ′ ′
a(x)u (x)v (x)dx = f (x)v(x)dx, ∀v(x) ∈ H01 . (4.1.5)
0 0
In other words we have shown that if u satisfies (BVP), then u also satisfies
the (VF) above. We write this as (BVP) =⇒ (VF). Now the question
is whether the reverse implication is true, i.e. under which conditions can
we deduce the implication (VF) =⇒ (BVP)? It appears that this question
has an affirmative answer, provided that the solution u to (VF) is twice
differentiable. Then, modulo this regularity requirement, the two problems
are indeed equivalent. We prove this in the following theorem.
Theorem 4.1. The following two properties are equivalent
i) u satisfies (BVP)
ii) u is twice differentiable and satisfies (VF).
Proof. We have already shown that (BVP) =⇒ (VF).
It remains to prove that (VF) =⇒ (BVP). Integrating by parts on the
left hand side in (4.1.5), assuming that u is twice differentiable, f ∈ C(0, 1),
a ∈ C 1 (0, 1), and using v(0) = v(1) = 0 we return to the relation (4.1.3):
Z 1 Z 1
− ′ ′
(a(x)u (x)) v(x)dx = f (x) v(x)dx, ∀v(x) ∈ H01 (4.1.6)
0 0
4.1. A DIRICHLET PROBLEM 55
1
g(x)
v ∗ (x)
x
0 ξ−δ ξ ξ+δ 1
Figure 4.1: The hat function v ∗ (x) over the interval (ξ − δ, ξ + δ).
with v ∗ (ξ) = 1 and the support Iδ , see Fig 4.1. Then v ∗ (x) ∈ H01 and
Z 1n ′ o Z
′ ∗
− a(x)u (x) − f (x) v (x)dx = g(x) v ∗ (x) dx > 0.
0 Iδ |{z} | {z }
>0 >0
This contradicts (4.1.7). Thus our claim is true. Note further that in (VF)
u ∈ H01 implies that u(0) = u(1) = 0 and hence we have also the boundary
conditions and the proof is complete.
56 CHAPTER 4. TWO-POINT BOUNDARY VALUE PROBLEMS
The minimization problem (MP). For the problem (4.1.1), we may for-
mulate yet another equivalent problem, viz:
Find u ∈ H01 such that F (u) ≤ F (w), ∀w ∈ H01 , where F (w) is the total
potential energy of the displacement w(x), given by
Z Z 1
1 1 ′ 2
(MP) F (w) = a(w ) dx − f wdx. (4.1.12)
2 0 0
Internal (elastic) energy Load potential
This means that the solution u minimizes the energy functional F (w). Below
we show that the above minimization problem is equivalent to the variational
formulation (VF) and hence also to the boundary value problem (BVP).
i.e.
Z 1 Z 1
′ ′
au v dx = f vdx, ∀v ∈ H01 ⇐⇒ F (u) ≤ F (w), ∀w ∈ H01 . (4.1.13)
0 0
Proof. (=⇒): First we show that the variational formulation (VF) implies
the minimization problem (MP). To this end, for w ∈ H01 we let v = w − u,
4.1. A DIRICHLET PROBLEM 57
then, since H01 is a vector space and u ∈ H01 , hence v ∈ H01 and
Z Z 1
1 1 ′
2
F (w) = F (u + v) = a (u + v) dx − f (u + v)dx =
2 0 0
Z Z Z
1 1 1 1 ′ 2 1 1
= ′ ′
2au v dx + a(u ) dx + a(v ′ )2 dx
2 0 2 0 2 0
| {z } | {z }
(i) (ii)
Z 1 Z 1
− f udx − f vdx.
0 0
| {z } | {z }
(iii) (iv)
Now using (VF) we have (i) − (iv) = 0. Further by the definition of the
functional F , (ii) − (iii) = F (u). Thus
Z
1 1
F (w) = F (u) + a(x)(v ′ (x))2 dx, (4.1.14)
2 0
and since a(x) > 0 we get F (w) ≥ F (u), thus we have proved ” =⇒ ” part.
(⇐=): Next we show that the minimization problem (MP) implies the vari-
ational formulation (VF). To this end, assume that F (u) ≤ F (w) ∀w ∈ H01 ,
and for an arbitrary function v ∈ H01 , set gv (ε) = F (u + εv), then by(MP), g
∂
(as a function of ε) has a minimum at ε = 0. In other words ∂ε gv (ε) = 0.
ε=0
We have that
Z Z 1
1 1 ′
2
gv (ε) = F (u + εv) = a (u + εv) dx − f (u + εv)dx =
2 0 0
Z Z 1 Z 1
1 1 ′ 2 2 ′ 2 ′ ′
= {a(u ) + aε (v ) + 2aεu v }dx − f udx − ε f vdx.
2 0 0 0
∂gv
The derivative ∂ε
(ε),
of g(ε, v) is
Z Z 1
∂gv 1 1 ′ 2 ′ ′
(ε) = {2aε(v ) + 2au v }dx − f vdx, (4.1.15)
∂ε 2 0 0
∂gv
where ∂ε = 0, yields
(ε=0)
Z 1 Z 1
′ ′
au v dx − f vdx = 0, (4.1.16)
0 0
Corollary 4.2.
(BV P ) ” ⇐⇒ ” (V F ) ⇐⇒ (M P ).
Recall that ” ⇐⇒ ” is a conditional equivalence, requiring u to be twice
differentiable, for the reverse implication.
x
x0 = 0 x1 x2 xk−1 xk xM xM +1 = 1
hk
Let C(I, P1 (Ik )) denote the set of all continuous piecewise linear functions on
Th (continuous in the whole interval I, linear on each subinterval Ik ), and
define
Vh0 = {v : v ∈ C(I, P1 (Ik )), v(0) = v(1) = 0}. (4.2.1)
Note that Vh0 is a finite dimensional (dimVh0 = M ) subspace of
n Z 1 o
H01 = v(x) : 2 ′ 2
(v(x) + v (x) )dx < ∞, and v(0) = v(1) = 0 . (4.2.2)
0
The finite element method (FEM) is a finite dimensional version of the vari-
ational formulation (VF), where the test functions are in a finite dimensional
subspace Vh0 , of H01 , spanned by the hat-functions, ϕj (x), j = 1, . . . , M .
4.3. ERROR ESTIMATES IN THE ENERGY NORM 59
Thus, if in VF we restrict v to Vh0 (rather that H01 ) and subtract FEM from
it, we get the Galerkin orthogonality:
Z 1
a(x)(u′ (x) − u′h (x))v ′ (x)dx = 0, ∀v ∈ Vh0 . (4.2.4)
0
Now the purpose is to estimate the error arising in approximating the solution
for BV P by functions in Vh0 . To this approach we need some measuring
environment for the error. We recall the definition of Lp -norms:
Z 1 1/p
Lp -norm kvkLp = |v(x)|p dx , 1≤p<∞
0
L∞ -norm kvkL∞ = max |v(x)|,
x∈[0,1]
and also introduce: Z 1/2
1
Weighted L2 -norm kvka = a(x)|v(x)|2 dx , a(x) > 0
Z0 1 1/2
′ 2
Energy-norm kvkE = a(x)|v (x)| dx ,
0
Note that kvkE = kv ′ ka .
This means that the finite element solution uh ∈ Vh0 is the best approximation
of the solution u, in the energy norm, by functions in Vh0 .
60 CHAPTER 4. TWO-POINT BOUNDARY VALUE PROBLEMS
Proof. Since πh u(x) ∈ Vh0 , we may take v = πh u(x) in (4.3.1) and use, e.g.
the second estimate in the interpolation Theorem 3.3 (slightly generalized to
the weigthed norm k · ka , see remark below) to get
Remark 4.1. The interpolation theorem is not stated in the weighted norm.
The a(x) dependence of the interpolation constant Ci can be shown as follows
Z 1 1/2
′ ′
ku − (πh u) ka = a(x)(u′ (x) − (πh u)′ (x))2 dx
0
≤ max a(x)1/2 · ku′ − (πh u)′ kL2 ≤ ci max a(x)1/2 khu′′ kL2
x∈[0,1] x∈[0,1]
Z 1 1/2
= ci max a(x)1/2 h(x)2 u′′ (x)2 dx
x∈[0,1] 0
Z
(maxx∈[0,1] a(x) ) 1
1/2
2 ′′ 2
1/2
≤ ci · a(x)h(x) u (x) dx .
(minx∈[0,1] a(x)1/2 ) 0
Thus
(maxx∈[0,1] a(x)1/2 )
C i = ci , (4.3.7)
(minx∈[0,1] a(x)1/2 )
where ci = c2 is the interpolation constant in the second estimate in Theorem
3.3.
Remark 4.2. If the objective is to divide [0, 1] into a finite number of subin-
tervals, then one can use the result of Theorem 4.4: to obtain an optimal
partition of [0, 1], where whenever a(x)u′′ (x)2 gets large we compensate by
making h(x) smaller. This, however, “requires that the exact solution u(x)
is known” 1 . Now we state the a posteriori error estimate, which instead of
the unknown solution u(x), uses the residual of the computed solution uh (x).
where R(uh (x)) = f + (a(x)u′h (x))′ is the residual, and u(x) − uh (x) ∈ H01 .
Proof. By the definition of the energy norm we have
Z 1 Z 1
2 ′ 2
ke(x)kE = a(x)(e (x)) dx = a(x)(u′ (x) − u′h (x))e′ (x)dx
Z0 1 0
Z 1 (4.3.9)
′ ′
= a(x)u (x)e (x)dx − a(x)u′h (x)e′ (x)dx
0 0
Adding and subtracting the interpolant πh e(x) and its derivative (πh e)′ (x)
to e and e′ in the integrands above yields
Z 1 Z 1
2
ke(x)kE = f (x)(e(x) − πh e(x))dx + f (x)πh e(x)dx
0 0
| {z }
(i)
Z 1 Z 1
− a(x)u′h (x)(e′ (x) ′
− (πh e) (x))dx − a(x)u′h (x)(πh e)′ (x)dx .
0
|0 {z }
(ii)
Since uh (x) is the solution of the (FEM) given by (4.2.3) and πh e(x) ∈ Vh0
we have that −(ii) + (i) = 0. Hence
Z 1 Z 1
2
ke(x)kE = f (x)(e(x) − πh e(x))dx − a(x)u′h (x)(e′ (x) − (πh e)′ (x))dx
0 0
Z 1 M
X +1 Z x k
= f (x)(e(x) − πh e(x))dx − a(x)u′h (x)(e′ (x) − (πh e)′ (x))dx.
0 k=1 xk−1
4.3. ERROR ESTIMATES IN THE ENERGY NORM 63
Now let R(uh (x)) = f (x) + (a(x)u′h (x))′ , i.e. R(uh (x)) is the residual error,
which is a well-defined function except in the set {xk }, k = 1, . . . , M ; where
(a(xk )u′h (xk ))′ is not defined. Then, using Cauchy-Schwarz’ inequality we get
the following estimate
Z 1
ke(x)k2E = R(uh (x))(e(x) − πh e(x))dx =
0
Z 1 e(x) − π e(x)
p
1 h
= p h(x)R(uh (x)) · a(x) dx
0 a(x) h(x)
Z 1 1 1/2 Z 1 e(x) − π e(x) 2 1/2
2 2 h
≤ h (x)R (uh (x))dx a(x) dx .
0 a(x) 0 h(x)
64 CHAPTER 4. TWO-POINT BOUNDARY VALUE PROBLEMS
To estimate (4.3.12) we can use the third interpolation estimate (in Theorem
5.5) for e(x) in each subinterval and get
e(x) − π e(x)
h
≤ Ci ke′ (x)ka = Ci ke(x)kE , (4.3.13)
h(x) a
Adaptivity
Below we briefly outline the adaptivity procedure based on the a posteriori
error estimate which uses the approximate solution and which can be used
for mesh-refinements. Loosely speaking, the estimate (4.3.8) predicts local
mesh refinement, i.e. indicates the regions (subintervals) which should be
subdivided further. More specifically the idea is as follows: assume that one
seeks an error less than a given error tolerance TOL > 0:
Then, one may use the following steps as a mesh refinement strategy:
(ii) Compute the corresponding FEM solution uh (x) and residual R(uh (x)).
1
(iii) If kekE > TOL, refine the mesh in the places where R2 (uh (x)) is
a(x)
large and perform the steps (ii) and (iii) again.
4.4. FEM FOR CONVECTION–DIFFUSION–ABSORPTION BVPS 65
Since u(0) = α and u(1) = β are given, we need to take the trial functions in
V := {w : w ∈ H 1 , w(0) = α, w(1) = β},
and the test functions in
V 0 := H01 = {w : w ∈ H 1 , w(0) = w(1) = 0}.
We multiply the PDE by a test function v ∈ V 0 and integrate over (0, 1).
Integrating by parts we get
Z 1 Z 1
′ ′ ′ ′
− u (1)v(1) + u (0)v(0) + u v dx + 4 uv dx = 0 ⇐⇒
0 0
Z 1 Z 1
(V F ) : Find u ∈ V so that ′ ′
u v dx + 4 uv dx = 0, ∀v ∈ V 0 .
0 0
66 CHAPTER 4. TWO-POINT BOUNDARY VALUE PROBLEMS
and
Note that here, the basis functions needed to represent functions in Vh are the
hat-functions ϕj , j = 0, . . . , n+1 (including the two half-hat-functions ϕ0 and
ϕn+1 ), whereas the basis functions describing Vh0 are ϕi :s for i = 1, . . . , n,
i.e. all full-hat-functions but not ϕ0 and ϕn+1 . This is due to the fact that
the values u(0) = α och u(1) = β are given and therefore we do not need to
determine those two nodal values approximately.
ϕ0 ϕ1 ϕj ϕn ϕn+1
and
1 x − xn nh ≤ x ≤ (n + 1)h
ϕn+1 (x) = .
h 0, else.
Inserting uh into (FEM), and choosing v = ϕi (x), i = 1, . . . , n we get
n Z
X 1 Z 1
ϕ′j (x)ϕ′i (x) dx +4 ϕj (x)ϕi (x) dx cj
j=1 0 0
Z 1 Z 1
=− ϕ′0 (x)ϕ′i (x) dx +4 ϕ0 (x)ϕi (x) dx c0
0
Z 1 Z0 1
− ϕ′n+1 (x)ϕ′i (x) dx + 4 ϕn+1 (x)ϕi (x) dx cn+1 .
0 0
This, however, does not make any difference in the current example, since,
as seen, both S and M are symmetric. To compute the entries of M , we
follow the same procedure as in Chapter 2, and notice that, as S, also M is
symmetric and its elements mij are
R
1
ϕ ϕ dx = 0, ∀i, j with |i − j| > 1
R0 i j
1 2
mij = mji = ϕj (x) dx, for i=j (4.4.3)
R
0
1 ϕ (x)ϕ (x),
0 j j+1 for i = j + 1.
x
xj−1 xj xj+1 xj+2
Z Z Z xj+1
1
2 1 xj 2
mjj = ϕj (x) dx = 2 (x − xj−1 ) dx + (xj+1 − x)2
0 h xj−1 xj
h
1 (x − xj−1 ) 3 ix j h
1 (xj+1 − x) 3 ixj+1
= 2 − 2
h 3 xj−1 h 3 xj
3 3
1 h 1 h 2
= 2· + 2· = h, j = 1, . . . , n,
h 3 h 3 3
(4.4.4)
4.4. FEM FOR CONVECTION–DIFFUSION–ABSORPTION BVPS 69
Remark 4.3. An easier way to compute the above integrals mj,j+1 (as well
as mjj ) is through Simpson’s rule, which is exact for polynomials of degree
≤ 2. Since ϕj (x)ϕj+1 (x) = 0 at x = xj and x = xj+1 , we need to evaluate
only the midterm of the Simpson’s formula, i.e.
Z 1
h xj + xj+1 x + x
j j+1 h 1 1 h
ϕj ϕj+1 dx = 4 ϕj · ϕj+1 ·=4· · · = .
0 6 2 2 6 2 2 6
For a uniform partition one may use ϕ0 = 1 − x/h and ϕ1 = x/h on (0, h) :
Z 1 Z h h Z h
x x x x2 i h (−1) x2 h
ϕ0 ϕ1 dx = (1 − ) dx = (1 − ) − · dx = .
0 0 h h h 2h 0 0 h 2h 6
Example 4.2. Below we consider a convection-diffusion problem:
where ε and p are positive real numbers and r ∈ R. Here −εu′′ is the diffusion
term, pu′ corresponds to convection, and r is a given (here for simplicity a
constant) source (r > 0) or sink (r < 0). We would like to answer the same
question as in the previous example. This time with c0 = u(0) = 0. Then,
the test function at x = 0; ϕ0 will not be necessary. But since u(1) is not
given, we shall need the test function at x = 1: ϕn+1 . The function space for
the continuous solution: the trial function space, and the test function space
are both the same:
Z 1
2 ′ 2
V := w : w(x) + w (x) dx < ∞, and w(0) = 0 .
0
We multiply the PDE by a test function v ∈ V and integrate over (0, 1).
Then, integration by parts yields
Z 1 Z 1 Z 1
′ ′ ′ ′ ′
−εu (1)v(1) + εu (0)v(0) + ε u v dx + p u vdx = r v dx.
0 0 0
ϕ0 ϕ2 ϕj ϕn ϕn+1
To compute the entries for C, we note that like, S, M and S̃, also C is a
tridiagonal matrix. But C is anti-symmetric. Its entries are
cij = 0, for |i − j| > 1
R
cii = 01 ϕi (x)ϕ′i (x) dx = 0, for i = 1, . . . , n
R1
cn+1,n+1 = 0 ϕn+1 (x)ϕ′n+1 (x) dx = 1/2, (4.4.5)
R
1
ci,i+1 = 0 ϕi (x)ϕ′i+1 (x) dx = 1/2, for i = 1, . . . , n
R
c 1
i+1,i= 0
ϕ (x)ϕ′ (x) dx = −1/2,
i+1 i for i = 1, . . . , n.
Thus,
0 1 0 0 ... 0 1 0
−1 0 1 0 ... 0 1 0
1 0 −1 0 1 ... 0 1 0
C=
,
b = rh
+ εβ
.
2 ... ... ... ... ... ... · ·
0 . . . . . . −1 0 1 1 0
0 ... ... ... −1 1 1/2 1
Remark 4.4. In the convection dominated case pε << 1 this standard FEM
will not work. Spurious oscillations in the approximate solution will appear.
The standard FEM has to be modified in this case.
4.5 Exercises
Problem 4.1. Consider the two-point boundary value problem
Let V = {v : kvk+kv ′ k < ∞, v(0) = v(1) = 0}, k·k denotes the L2 -norm.
a. Use V to derive a variational formulation of (4.5.1).
4.5. EXERCISES 73
Divide the interval 0 < x < 1 into 3 subintervals of equal length h = 13 and
let Vh be the corresponding space of continuous piecewise linear functions
vanishing at x = 0.
a. Use Vh to formulate a finite element method for (4.5.9).
b. Verify that the stiffness matrix A and the load vector b are given by
16 −9 0 0
1
A = −9 20 −11 , b = 0 .
2
0 −11 11 1
Problem 4.14. Show that the FEM with the mesh size h for the problem:
−u′′ = 1 0 < x < 1
(4.5.14)
u(0) = 1 u′ (1) = 0,
with
U (x) = 7ϕ0 (x) + U1 ϕ1 (x) + . . . + Um ϕm (x). (4.5.15)
leads to the linear system of equations: Ã · Ũ = b̃, where
−1 2 −1 0 7 h
0 −1 2 −1 . . . U1 ...
1
,
,
,
à = . . . . . . . . . ... Ũ = ... b̃ = h
h
0 ... 0 ... Um h/2
m × (m + 1) (m + 1) × 1 m×1
Problem 4.15. Prove an a priori error estimate for the cG(1) finite element
method for the problem
c) Show that, with these special choices, the computed solution is equal to the
exact one, i.e. the error is equal to 0.
Problem 4.17. Prove an a priori error estimate for the finite element
method for the problem
Problem 4.18. (a) Prove an a priori error estimate for the cG(1) approxi-
mation of the boundary value problem
where c ≥ 0 is constant.
(b) For which value of c is the a priori error estimate optimal?
4.5. EXERCISES 79
−u′′ (x) + 2xu′ (x) + 2u(x) = f (x), x ∈ (0, 1), u(0) = u(1) = 0,
in a partition Th of the interval [0, 1]. Set e = u − U and derive a priori error
estimates in the energy-norm:
Z 1
2 ′ 2 2 2
||e||E = ||e || + ||e|| , where ||w|| = w(x)2 dx.
0
80 CHAPTER 4. TWO-POINT BOUNDARY VALUE PROBLEMS
Chapter 5
(DE) u̇(t) + a(t)u(t) = f (t), 0 < t ≤ T,
(5.0.1)
(IV) u(0) = u , 0
du
where f (t) is the source term and u̇(t) = . The coefficient a(t) is a bounded
dt
function. If a(t) ≥ 0 the problem (5.0.1) is called parabolic, while a(t) ≥ α > 0
yields a dissipative problem, in the sense that, with increasing t, perturbations
of solutions to (5.0.1), e.g. introduced by numerical discretization, will decay.
In general, in numerical approximations for (5.0.1), the error accumulates when
advancing in time, i.e. the error of previous time steps adds up to the error of
the present time step. The different types of error accumulation/perturbation
growth are referred to as stability properties of the initial value problem.
81
82 CHAPTER 5. SCALAR INITIAL VALUE PROBLEMS
i.e. Z t
A(t) A(0)
u(t)e − u(0)e = eA(s) f (s)ds.
0
Now since A(0) = 0 and u(0) = u0 we get the desired result
Z t
−A(t)
u(t) = u0 e + e−(A(t)−A(s)) f (s)ds. (5.1.3)
0
Thus e−A(t) ≤ e−αt and e−(A(t)−A(s)) ≤ e−α(t−s) . Hence, using (5.1.3) we get
Z t
−αt
|u(t)| ≤ |u0 |e + e−α(t−s) |f (s)|ds, (5.1.6)
0
which yields
h1 is=t
−αt −α(t−s)
|u(t)| ≤ e |u0 | + max |f (s)| e , i.e.
0≤s≤t α s=0
1
|u(t)| ≤ e−αt |u0 | + (1 − e−αt ) max |f (s)|.
α 0≤s≤t
(ii) Let α = 0 Zin (5.1.6) (which is true also in this case: for α = 0), then
t
|u(t)| ≤ |u0 | + |f (s)|ds, and the proof is complete.
0
Remark 5.1. (i) expresses that the effect of the initial data u0 decays expo-
nentially with time, and that the effect of the source term f on the right hand
side does not depend on the length of the time interval, only on the maximum
value of f , and on the value of α. In case (ii), the influence of u0 remains
bounded in time, and the integral of f indicates an accumulation in time.
t0 = 0 t1 t2 t3 tN = T
Example 5.1. Now we discretize the IVP (5.0.1), for a(t) being positive
constant, with the backward Euler method, on the partition Tk , approximat-
ing the derivative u̇(t) by a backward-difference quotient at each subinterval
Ik = (tk−1 , tk ] by u̇(t) ≈ u(tktk)−u(t
−tk−1
k−1 )
. Then an approximation of (5.0.1), with
f (t) ≡ 0 is given by
u(tk ) − u(tk−1 )
= −a · u(tk ), k = 1, . . . , N, and u(0) = u0 . (5.2.1)
tk − tk−1
(Note that in forward Euler, we would have −au(tk−1 ) on the right hand side
of (5.2.1)). Letting ∆tk = tk − tk−1 , (5.2.1) yields
Starting with k = 1 and the data u(0) = u0 , the solution u(tk ) would, itera-
tively, be computed at the subsequent points: t1 , t2 , . . . , tN = T .
For a uniform partition, where all subintervals have the same length ∆t, and
since for a > 0, 1 + a∆t > 0 (6= 0), (5.2.2) can be written as
Remark 5.2. Note that, for the problem (5.0.1), with f (t) ≡ 0, in the
Example 2.1 we just replace λ with −a, and get the forward (explicit) Euler
method:
u(tk ) = (1 − a∆t)k u0 . (5.2.4)
Example 5.2. Now we introduce the Crank-Nicolson method for the finite
difference approximation of (5.0.1). Here, first we integrate the equation
(5.0.1) over Ik = [tk−1 , tk ] to get
Z tk Z tk
u(tk ) − u(tk−1 ) + a u(t) dt = f (t) dt. (5.2.5)
tk−1 tk−1
5.2. FINITE DIFFERENCE METHODS 85
Then, approximate the integral term by the simple trapezoidal rule we get
Z tk
∆tk
u(tk ) − u(tk−1 ) + a (u(tk ) + u(tk−1 )) = f (t) dt. (5.2.6)
2 tk−1
Or, equivalently,
Z tk
1 − a∆tk /2 1
u(tk ) = u(tk−1 ) + f (t) dt.
1 + a∆tk /2 1 + a∆tk /2 tk−1
Let us assume a zero source term (f = 0), and uniform partition, i.e. ∆tk =
∆t for k = 1, 2, . . . , N , then we have the following Crank-Nicolson method:
1 − a∆t/2 k
u(tk ) = u0 . (5.2.7)
1 + a∆t/2
Example 5.3. Consider the initial value problem:
u̇(t) + au(t) = 0, t > 0, u(0) = 1.
a) Let a = 40, and the time step k = 0.1. Draw the graph of Un :=
U (nk), k = 1, 2, . . . , approximating u using (i) explicit (forward) Euler, (ii)
implicit (Backward) Euler, and (iii) Crank-Nicolson methods.
b) Consider the case a = i, (i2 = −1), having the complex solution u(t) = e−it
with |u(t)| = 1 for all t. Show that this property is preserved in Crank-
Nicolson approximation, (i.e. |Un | = 1 ), but NOT in any of the Euler
approximations.
Solution: a) With a = 40 and k = 0.1 we get the explicit Euler:
U −U + 40 × (0.1)U = 0, U = −3U , n = 1, 2, . . . ,
n n−1 n−1 n n−1
=⇒
U = 1. U = 1.
0 0
Implicit Euler:
U = 1
U = 15 Un−1 , n = 1, 2, 3, . . . ,
n 1+40×(0.1) n−1
U = 1.
0
86 CHAPTER 5. SCALAR INITIAL VALUE PROBLEMS
Cranck-Nicolson:
Un = 1− 21 ×40×(0.1)
U
1+ 21 ×40×(0.1) n−1
= − 13 Un−1 , n = 1, 2, 3, . . . ,
U = 1.
0
E.E.
1 I.E.
10
1 C.N.
1/5
1
k 2k 3k 3k k 2k 3k
k 2k
−3 −1/3
b) With a = i we get
Explicit Euler
√
|Un | = |1 − (0.1) × i||Un−1 | = 1 + 0.01|Un−1 | =⇒ |Un | ≥ |Un−1 |.
Implicit Euler
1 1
|Un | = |Un−1 | = √ |Un−1 | ≤ |Un−1 |.
1 + (0.1) × i 1 + 0.01
Crank-Nicolson
1 − 1 (0.1) × i
2
|Un | = 1 |Un−1 | = |Un−1 |.
1 + 2 (0.1) × i
over the whole time interval (0, T ) is referred as the global Galerkin method.
In this section, first we introduce two versions of the global Galerkin method
and then extend them to partitions of the interval (0, T ) using piecewise
polynomial test (multiplier) and trial (solution) functions. Here, we shall
focus on two simple, low degree polynomial, approximation cases.
• The continuous Galerkin method of degree 1; cG(1). In this case the trial
functions are piecewise linear and continuous while the test functions are
piecewise constant and discontinuous, i.e. unlike the cG(1) for BVP, here
the trial and test functions belong to different polynomial spaces.
• The discontinuous Galerkin method of degree 0; dG(0). Here both the trial
and test functions are chosen to be piecewise constant and discontinuous.
The exact solution is given by u(t) = e−t . The continuous piecewise linear
approximation, with the ansatz U (t) = 1 + ξ1 t in,
Z 1
(U̇ (t) + U (t))v(t) dt = 0, (5.3.4)
0
U1 (t)
u(t) = e−t
U2 (t)
t
1
T −t t
U (t) = U (0) + U (T ) . (5.3.6)
T T
Inserting (5.3.6) into (5.3.5) we get
Z Z T
T
T −t t
U (T ) − U (0) + a U (0) + U (T ) dt = f dt, (5.3.7)
0 T T 0
which is an equation for the unknown quantity U (T ). Thus, using (5.3.6) with
a given U (0), we get the linear approximation U (t) for all t ∈ [0, T ]. Below
we generalize this example to piecewise linear approximation and demonstrate
the iteration procedure for the cG(1) scheme.
The cG(1) Algorithm
For a partition Tk of the interval [0, T ] into subintervals Ik = (tk−1 , tk ], we
perform the following steps:
(1) Given U (0) = U0 = u0 and a source term f , apply (5.3.7) to the first
subinterval (0, t1 ] and compute U (t1 ). Then, using (5.3.6) one gets
U (t), ∀t ∈ [0, t1 ].
(2) Assume that we have computed Uk−1 := U (tk−1 ). Hence, Uk−1 and
f are now considered as data. Now we consider the problem on the
subintervals Ik = (tk−1 , tk ], and compute the unknown Uk := U (tk )
from the local version of (5.3.7),
Z t −t Z tk
tk
k t − tk−1
Uk − Uk−1 + a Uk−1 + Uk dt = f dt.
tk−1 tk − tk−1 tk − tk−1 tk−1
Having both Uk−1 and Uk , by linearity, we get U (t) for t ∈ Ik . To get the
continuous piecewise linear approximation in the whole interval [0, tN ],
step (2) is performed in successive subintervals Ik , k = 2, . . . , N .
90 CHAPTER 5. SCALAR INITIAL VALUE PROBLEMS
where
(q)
Vk = {v : v continuous, piecewise polynomial of degree ≤ q on Tk },
(q−1)
Wk = {w : w discontinuous, piecewise polynomial, deg w ≤ q − 1 on Tk }.
So, the difference between the global continuous Galerkin method and cG(q)
is that now we have piecewise polynomials on a partition of [0, T ] rather than
global polynomials in the whole interval [0, T ].
This approach gives up the requirement that U (t) satisfies the initial condi-
tion. Instead, the initial condition is imposed in a variational sense by the
term (U (0) − u(0))v(0). As in the cG(q) case, to derive the discontinuous
Galerkin method of degree q: dG(q) scheme, the above strategy can be for-
mulated for the subintervals in a partition Tk . To this end, we recall the
notation for the right/left limits: vn± = lim+ v(tn ± s) and the corresponding
s→0
jump term [vn ] = vn+ − vn− at time level t = tn . Then, the dG(q) method for
(5.0.1) reads as follows: for n = 1, . . . , N ; find U (t) ∈ P q (tn−1 , tn ) such that
Z tn Z tn
+ + +
(U̇ + aU )vdt + Un−1 vn−1 = −
f vdt + Un−1 vn−1 , ∀v ∈ P q (tn−1 , tn ).
tn−1 tn−1
(5.3.10)
5.3. GALERKIN FINITE ELEMENT METHODS FOR IVP 91
vn+ ◦ •
[vn ]
◦ •vn−
kn
tn−1 tn+1 t
tn
Figure 5.2: The jump [vn ] and the right and left limits vn±
Remark 5.3. One can show that cG(1) converges faster than dG(0), whereas
dG(0) has better stability properties than cG(1): More specifically, in the
parabolic case when a > 0 is constant and (f ≡ 0) we can easily verify
that (see Exercise 6.10 at the end of this chapter) the dG(0) solution Un
corresponds to the Backward Euler scheme
1 n
Un = u0 ,
1 + ak
and the cG(1) solution Uen is given by the Crank-Nicolson scheme:
1 n
en = 1 − 2 ak u0 ,
U
1 + 12 ak
where k is the constant time step.
92 CHAPTER 5. SCALAR INITIAL VALUE PROBLEMS
5.4 Exercises
Problem 5.1. (a) Derive the stiffness matrix and load vector in piecewise
polynomial (of degree q) approximation for the ODE of population dynamics:
(b) Let λ = 1 and u0 = 1 and determine the approximate solution U (t), for
q = 1 and q = 2.
corresponding to
(a) a(t) = 4, (b) a(t) = −t.
Problem 5.4. Compute the cG(1) approximation for the differential equa-
tions in the above problem. In each case, determine the condition on the step
size that guarantees that U exists.
Problem 5.5. Without using the solution Theorem 5.1, prove that if a(t) ≥ 0
then, a continuously differentiable solution of (5.0.1) is unique.
Show that for a(t) > 0, and for N = 1, 2, . . . , the piecewise linear approxi-
mate solution U for this problem satisfies the error estimate
Assume a constant time step k and verify the iterative formulas for dG(0)
and cG(1) approximations U and Ũ , respectively: i.e.
1 n 1 − ak/2 n
Un = u0 , Ũn = u0 .
1 + ak 1 + ak/2
Problem 5.10. Formulate the dG(1) method for the differential equations
specified in Problem 5.3.
Problem 5.11. Write out the a priori error estimates for the equations
specified in Problem 5.3.
Problem 5.12. Use the a priori error bound to show that the residual of the
dG(0) approximation satisfies R(U ) = O(1).
Problem 5.13. Prove the following stability estimate for the dG(0) method
described by (5.3.12),
N
X −1
2
|UN | + |[Un ]|2 ≤ |u0 |2 .
n=0
94 CHAPTER 5. SCALAR INITIAL VALUE PROBLEMS
Chapter 6
95
96 CHAPTER 6. INITIAL BOUNDARY VALUE PROBLEMS IN 1D
u(x, t)
u0 (x)
tn−1
tn
t
Figure 6.1: A decreasing temperature profile with data u(0, t) = u(1, t) = 0.
Example 6.1. Describe the physical meaning of the functions and parame-
ters in the problem (6.1.1), when f = 20 − u.
where u0 and u′0 are assumed to be L2 (I) functions with I = (0, 1). Note
further that, here || • (·, t)|| is the time dependent L2 norm:
Z 1 1/2
2
||w(·, s)|| := ||w(·, s)||L2 (0,1) = ||w(x, s)|| dx .
0
Proof. Multiply the equation in (6.1.1) by u and integrate over (0, 1) to get
Z 1 Z 1 Z 1
′′
u̇u dx − u u dx = f u dx. (6.1.4)
0 0 0
Note that u̇u = 21 dtd u2 . Hence, integration by parts in the second integral
yields
Z Z 1 Z 1
1d 1 2 ′ 2 ′ ′
u dx + (u ) dx − u (1, t)u(1, t) + u (0, t)u(0, t) = f u dx.
2 dt 0 0 0
Now since ||u′ ||2 ≥ 0, consequently ||u|| dtd ||u|| ≤ ||f || ||u||, and thus
d
||u|| ≤ ||f ||. (6.1.6)
dt
Relabeling the variable from t to s, and integrating over time we end up with
Z t
||u(·, t)|| − ||u(·, 0)|| ≤ ||f (·, s)|| ds, (6.1.7)
0
98 CHAPTER 6. INITIAL BOUNDARY VALUE PROBLEMS IN 1D
which yields the first assertion (6.1.2) of the theorem. To prove (6.1.3) we
multiply the differential equation by u̇, integrate over (0, 1), and use integra-
tion by parts so that we have on the left hand side
Z 1 Z 1 Z 1
2 ′′ 2
(u̇) dx − u u̇ dx = ||u̇|| + u′ u̇′ dx − u′ (1, t)u̇(1, t) + u′ (0, t)u̇(0, t).
0 0 0
where in the last step we used the Cauchy-Schwarz inequality. Thus, squaring
both sides and integrating, we get
Z L Z L Z L Z L
2 2 2
u(x) dx ≤ L ′
|u (y)| dy dx = L |u′ (y)|2 dy, (6.1.13)
0 0 0 0
and hence
||u|| ≤ L||u′ ||. (6.1.14)
d
a) ||u||2 + 2||u′ ||2 = 0, b) ||u(·, t)|| ≤ e−t ||u0 ||.
dt
Proof. a) Multiply the equation by u and integrate over x ∈ (0, 1), to get
Z 1 Z 1 Z 1
0= ′′
(u̇ − u )u dx = u̇u dx + (u′ )2 dx − u′ (1, t)u(1, t) + u′ (0, t)u(0, t),
0 0 0
where we used integration by parts. Using the boundary data we then have
Z Z 1
1d 1 2 1d
u dx + (u′ )2 dx = ||u||2 + ||u′ ||2 = 0.
2 dt 0 0 2 dt
100 CHAPTER 6. INITIAL BOUNDARY VALUE PROBLEMS IN 1D
This gives the proof of a). As for the proof of b), using a) and the Poincare
inequality, with L = 1, i.e., ||u|| ≤ ||u′ || we get
d
||u||2 + 2||u||2 ≤ 0. (6.1.17)
dt
Multiplying both sides of (6.1.17) by the integrating factor e2t yields
d 2 2t
d
||u|| e = ||u|| + 2||u|| e2t ≤ 0.
2 2
(6.1.18)
dt dt
We replace t by s and integrate with respect to s, over (0, t), to obtain
Z t
d
||u||2 e2s ds = ||u(·, t)||2 e2t − ||u(·, 0)||2 ≤ 0. (6.1.19)
0 ds
This yields
||u(·, t)||2 ≤ e−2t ||u0 ||2 =⇒ ||u(·, t)|| ≤ e−t ||u0 ||, (6.1.20)
The Variational formulation for this problem reads as follows: For every time
interval In = (tn−1 , tn ], find u(x, t), x ∈ (0, 1), t ∈ In , such that
Z Z 1 Z Z 1
′ ′
(u̇v + u v )dxdt = f vdxdt, ∀v : v(0, t) = v(1, t) = 0. (VF)
In 0 In 0
where
t − tn−1 tn − t
Ψn (t) = , Ψn−1 (t) = , (6.1.23)
kn kn
and
with ϕj being the usual continuous, piecewise linear finite element basis
functions (hat-functions) corresponding to a partition of Ω = (0, 1), with
0 = x0 < · · · < xℓ < xℓ+1 < · · · < xm+1 = 1, and ϕj (xi ) := δij . Now the
Galerkin method (FEM) is to determine the unknown coefficients Un,ℓ in the
above representation for U (U is a continuous, piecewise linear function both
in space and time variables) that satisfies the following discrete variational
formulation: Find U (x, t) given by (6.1.22) such that
Z Z 1 Z Z 1
′
(U̇ ϕi + U ϕ′i ) dxdt = f ϕi dxdt, i = 1, 2, . . . , m. (6.1.25)
In 0 In 0
Note that, on In = (tn−1 , tn ] and with Un (x) := U (x, tn ) and Un−1 (x) :=
U (x, tn−1 ),
Un − Un−1
U̇ (x, t) = Un−1 (x)Ψ̇n−1 (t) + Un (x)Ψ̇n (t) = . (6.1.26)
kn
U ′ (x, t) = Un−1
′
(x)Ψn−1 (t) + Un′ (x)Ψn (t).(6.1.27)
R
Inserting (6.1.26) and (6.1.27) into (6.1.25) we get using the identities, In dt =
R R
kn and In Ψn dt = In Ψn−1 dt = kn /2 that,
Z 1 Z 1 Z Z 1
′
Un ϕi dx − Un−1 ϕi dx + Ψn−1 dt Un−1 ϕ′i dx
|0 {z } | 0 {z } | In {z } | 0 {z }
M ·Un M ·Un−1 kn /2 S·Un−1
Z Z 1 Z Z 1
(6.1.28)
+ Ψn dt Un′ ϕ′i
dx = f ϕi dxdt .
In
| {z } | 0 {z } | In 0
{z }
kn /2 S·Un Fn
102 CHAPTER 6. INITIAL BOUNDARY VALUE PROBLEMS IN 1D
1 (x)
0
0 1
1 0
0
1 U
0
1
n+1
0 1
1 0
0
1
y ψ
n+1(t) 0
1
0
1 0
1
ψ (t ) 0 1
1 0
0
1
n
0
1
0
1 0
1
t
0U (x)1
1 0
0
1
0
1
n
t n+1 0 1
1 0
0ϕ
1
1
tn
0
1
0
1 i
(x)
t n-1
x
x i-1 xi x i+1
where M and S (computed below) are known as the mass-matrix and stiffness-
matrix, respectively, and
U F
n,1 n,1
Z Z 1
Un,2 Fn,2
Un =
,
F =
,
Fn,i = f ϕi dx dt. (6.1.30)
... ... In 0
Un,m Fn,m
Thus, given the source term f we can determine the vector Fn and then,
for each n = 1, . . . N , given the vector Un−1 (the initial value is given by
6.1. HEAT EQUATION IN 1D 103
Un′ (x) = Un,1 ϕ′1 (x) + Un,2 ϕ′2 (x) + . . . + Un,m ϕ′m (x). (6.1.31)
Hence, to compute the mass matrix M one should drop all derivatives from
the general form of the matrix for S given by (6.1.32). In other words unlike
104 CHAPTER 6. INITIAL BOUNDARY VALUE PROBLEMS IN 1D
R1
the form [SUn ]i = 0 Un′ ϕ′i , M Un does not involve any derivatives, neither in
Un nor in ϕi . Consequently
R R1 R1
1
ϕ1 ϕ1 ϕ1 ϕ2 . . . 0 ϕ1 ϕm
R 0 0
R1 R1
1
0 ϕ2 ϕ1 ϕ 2 ϕ 2 . . . ϕ2 ϕm
M =
0 0 .
(6.1.35)
... ... ... ...
R R R
1 1 1
0
ϕm ϕ1 0 ϕm ϕ2 . . . 0 ϕm ϕm
For a uniform partition, we have computed this mass matrix in Chapter 4:
2 1
0 0 ... 0 4 1 0 0 ... 0
3 6
1 2 1
6 0 ... 0 1 4 1 0 ... 0
3 6 h
M = h ... ... ... ... ... ... = ... ... ... ... ... ... .
6
1 2 1
0 ... ... 0 ... ... 1 4 1
6 3 6
1 2
0 ... ... ... 6 3
0 ... ... ... 1 4
6.1.3 Exercises
Problem 6.1. Derive a system of equations, as (6.1.29), for cG(1) − dG(0):
with the discontinuous Galerkin approximation dG(0) in time with piecewise
constants.
Problem 6.2. Let k · k denote the L2 (0, 1)-norm. Consider the problem
−u′′ = f, 0 < x < 1,
u′ (0) = v , u(1) = 0.
0
a) Show that the norms: ||u(·, t)|| and ||u′ (·, t)|| are non-increasing in time.
R 1/2
1 2
||u|| = 0
u(x) dx .
b) Show that ||u′ (·, t)|| → 0, as t → ∞.
c) Give a physical interpretation for a) and b).
Problem 6.6. Consider the inhomogeneous problem:
u̇ − εu′′ = f, 0 < x < 1, t > 0,
u(0, t) = ux (1, t) = 0, t > 0,
u(x, 0) = u (x),
0 0 < x < 1.
where f = f (x, t).
a) Show the stability estimate
Z t
||u(·, t)|| ≤ ||f (·, s)|| ds.
0
b) Show that for the corresponding stationary (u̇ ≡ 0) problem we have
1
||u′ || ≤ ||f ||.
ε
Problem 6.7. Give an a priori error estimate for the following problem:
(au′′ )′′ = f, 0 < x < 1, u(0) = u′ (0) = u(1) = u′ (1) = 0,
where a(x) > 0 on the interval I = (0, 1).
106 CHAPTER 6. INITIAL BOUNDARY VALUE PROBLEMS IN 1D
Therefore the total energy is conserved. We recall that 12 ||u̇||2 is the kinetic
energy, and 21 ||u′ ||2 is the potential (elastic) energy.
Problem 6.9. Derive a total conservation of energy relation using the Robin
type boundary condition: u′ + u = 0.
We may now set w = (u, v)t and rewrite the system (6.2.8) as ẇ + Aw = 0:
u̇ 0 −1 u 0
ẇ + Aw = + = . (6.2.9)
∂2
v̇ − ∂x 2 0 v 0
ψn(t) ϕ j (x)
1
Integrating by parts in x, in the second term, and using the boundary con-
dition u′ (1, t) = g(t) we get
Z 1 Z 1 Z 1
′′ ′ 1 ′ ′ ′
u ϕdx = [u ϕ]0 − u ϕ dx = g(t)ϕ(1, t) − u (0, t)ϕ(0, t) − u′ ϕ′ dx.
0 0 0
6.2. THE WAVE EQUATION IN 1D 109
Inserting the right hand side in (6.2.13) we get for all ϕ with ϕ(0, t) = 0:
Z Z 1 Z Z 1 Z
′ ′
v̇ϕ dxdt + u ϕ dxdt = g(t)ϕ(1, t) dt. (6.2.14)
In 0 In 0 In
and
Z Z 1
Vn (x) − Vn−1 (x)
ϕj (x) dxdt
In 0 kn
Z Z 1
′
+ Un−1 (x)Ψn−1 (t) + Un′ (x)Ψn (t) ϕ′j (x) dxdt (6.2.16)
In 0
Z
= g(t)ϕj (1) dt, for j = 1, 2, . . . , m,
In
Thus, the equations (6.2.15) and (6.2.16) are reduced to the iterative forms:
Z 1 Z
kn 1
Un (x)ϕj (x)dx − Vn (x)ϕj (x)dx
2 0
|0 {z } | {z }
M Un M Vn
Z 1 Z 1
kn
= Un−1 (x)ϕj (x)dx + Vn−1 (x)ϕj (x) dx, j = 1, 2, . . . , m,
0 2 0
| {z } | {z }
M Un−1 M Vn−1
110 CHAPTER 6. INITIAL BOUNDARY VALUE PROBLEMS IN 1D
and
Z 1 Z
kn 1 ′
Vn (x)ϕj (x)dx + U (x)ϕ′j (x) dx
2 0 n
|0 {z } | {z }
M Vn SUn
Z 1 Z 1
kn
= Vn−1 (x)ϕj (x) dx − U ′ (x)ϕ′j (x) dx +gn , j = 1, 2, . . . , m,
2 0 n−1
|0 {z } | {z }
M Vn−1 SUn−1
where Z
T
gn = (0, . . . , 0, gn,m ) , where gn,m = g(t) dt.
In
In compact form the vectors Un and Vn are determined by solving the linear
system of equations:
M U − kn M V = M U kn
n 2 n n−1 + 2 M Vn−1
(6.2.17)
kn SU + M V = − kn SU + MV +g ,
2 n n 2 n−1 n−1 n
6.2.3 Exercises
Problem 6.10. Derive the corresponding linear system of equations in the
case of time discretization with dG(0).
Problem 6.11 (discrete conservation of energy). Show that cG(1)-cG(1) for
the wave equation in system form with g(t) = 0, conserves energy: i.e.
Hint: Multiply the first equation by (Un−1 + Un )t SM −1 and the second equa-
tion by (Vn−1 +Vn )t and add up. Use then, e.g., the fact that Unt SUn = kUn′ k2 ,
where
Un,1
Un,2
Un = , and Un = Un (x) = Un,1 (x)ϕ1 (x) + . . . + Un,m (x)ϕm (x).
...
Un,m
Plot the solutions for the three cases t = 0.5, t = 1, t = 2, and with
1, x ∈ [2, 3]
u0 (x) = (6.2.21)
0, else
Problem 6.14. Apply cG(1) time discretization directly to the wave equation
by letting
U (x, t) = Un−1 Ψn−1 (t) + Un (x)Ψn (t), t ∈ In . (6.2.22)
Note that U̇ is piecewise constant in time and comment on:
Z Z 1 Z Z 1 Z
′ ′
Ü ϕj dxdt + u ϕj dxdt = g(t)ϕj (1)dt, j = 1, 2, . . . , m.
In 0 In 0 In
| {z } | {z } | {z }
? k
S(Un−1 +Un ) gn
2
Answers to Exercises
Chapter 1
1.5 b) No solution.
Chapter 2.
8 10 2
2.2 q = 1, U (t) = 1 + 3t. q = 2, U (t) = 1 + 11
t + 11
t.
30 45 2 35 3
q = 3, U (t) = 1 + 29
t + 116
t + 116
t.
q = 4, U (t) ≈ 1 + 0.9971t + 0.5161t2 + 0.1311t3 + 0.0737t4 .
2.3
P u(t) ≈ 0.9991 + 1.083t + 0.4212t2 + 0.2786t3 .
115
116 APPENDIX A. ANSWERS TO EXERCISES
2.4
8 −4 0
i
A = −4 8 −4 , b = (bi )3i=1 , bi = .
16
0 −4 8
2.6 a.
b. R(x) = (π 2 + 1)A sin πx + (4π 2 + 1)B sin 2πx + (9π 2 + 1)C sin 3πx − x
2 1 2
c. A = 2
,B=− 2
and C = .
π(π + 1) π(4π + 1) 3π(9π 2 + 1)
2.7 a. u(x) = 61 (π 3 − x3 ) + 21 (x2 − π 2 )
b. R(x) = −U ′′ (x) − x + 1 = 14 ξ0 cos x2 + 94 ξ1 cos 3x
2
c. ξ0 = 8(2π − 6)/π and ξ1 = 98 ( 29 − 32 π)/π.
Chapter 3.
3.2 (a) x, (b) 0.
3.3
4 − 11(x + π)/(2π), −π ≤ x ≤ − π2 ,
5/4 − (x + π )/(2π), − π2 ≤ x ≤ 0,
2
Π1 f (x) =
1 − 7x/(2π), 0 ≤ x ≤ π2 ,
3(x − π)/(2π), π
≤ x ≤ π.
2
3.7
2x − a − b a + b 2(x − a)
Π1 f (x) = f (a) + f( ) .
a−b 2 b−a
117
3.8 Hint: Use the procedure in the proof of Theorem 3.1, with somewhat
careful estimates at the end.
3.10
2
π4 e−8x ≈ 0.25x4 − 1.25x2 + 1.
(x − xi−1 )(x − ξi )
λi,2 (x) = , ξi ∈ (xi−1 , xi ).
(xi − xi−1 )(xi − ξi )
Chapter 4.
4.1 c) sin πx, x ln x and x(1 − x) are test functions of this problem. x2 and
ex − 1 are not test functions.
with h = 1/4.
b) A is invertible, therefore U is unique.
118 APPENDIX A. ANSWERS TO EXERCISES
4.8 a) No solution!
b) Trying to get a finite element approximation ends up with the matrix
equation
2 −2 0 ξ0 1
1
Aξ = f ⇐⇒ −2 4 −2 ξ1 = 2
4
0 −2 2 ξ2 1
4.12
2 −1 ξ1 4 1 ξ 1
3 + 1 1 = 1
−1 2 ξ2 18 1 4 ξ2 3 1
⇐⇒ (MATLAB) ξ1 = ξ2 = 0.102.
(aU ′ )′ = a′ U ′ + aU ′′ = 0.
Chapter 5.
j 1 1
5.1 a) aij = j+i
− j+i+1
, bi = i+1
, i, j = 1, 2, . . . ,
8 10 2
b) q = 1 : U (t) = 1 + 3t. q=2: U (t) = 1 + 11
t + 11
t.
1
5.3 a) u(t) = e−4t + 32
(8t2 − 4t + 1).
1 2
√ 1 2 Rx
t + √π2 e 2 t erf ( √t2 ),
2
b) u(t) = e 2 t − erf (x) = √2 e−y dy.
π 0
Chapter 6.
6.8 ||e|| ≤ ||h2 uxx ||
6.14
1 (u (x + 2t) + u (x − 2t)), x ≥ 2t
2 0 0
u(x, t) =
(u (2t + x) + u (2t − x)),
1
x < 2t
2 0 0
R R ct−x
x+ct
1
6.16 a) u(x, t) = 12 [u0 (x + ct) + u0 (ct − x)] + 2c 0
v 0 + 0
v0 .
1
Rt
b) u(x, t) = 2c 0
2c(t − s) ds = t2 /2.
6.19 a priori: ||e||H 1 ≤ Ci ||hu′′ || + ||h2 u′′ || .
6.20 a priori: ||e||E ≤ Ci ||hu′′ || + ||h2 u′′ || .
Appendix B
• The L2 -projection.
The Matlab codes are not optimized for speed, but rather intended to be easy
to read.
121
122 APPENDIX B. ALGORITHMS AND MATLAB CODES
M ξ = b.
4. Set
N
X
Ph f = ξj ϕj .
j=0
Below are two versions of Matlab codes for computing the mass matrix M:
%--------------------------------------------------------------------
% Syntax: M = MassMatrix(p, phi0, phiN)
% Purpose: To compute mass matrix M of partition p of an interval
% Data: p - vector containing nodes in the partition
% phi0 - if 1: include basis function at the left endpoint
% if 0: do not include a basis function
% phiN - if 1: include basis function at the right endpoint
% if 0: do not include a basis function
%--------------------------------------------------------------------
for i = 1:length(p)-1
h = p(i + 1) - p(i); % length of the current interval
M(i, i) = M(i, i) + h/3;
M(i, i + 1) = M(i, i + 1) + h/6;
M(i + 1, i) = M(i + 1, i) + h/6;
M(i + 1, i + 1) = M(i + 1, i + 1) + h/3;
end
ϕ0 (x) ϕ1 (x)
x
x0 = 0 x1 = h
Thus, for an arbitrary sub-interval Ik := [xk−1 , xk ] with the mesh size hk , and
basis functions ϕk and ϕk−1 (see Fig. 3.4.), the local mass matrix is given by
R R
ϕk−1 ϕk−1 Ik ϕk−1 ϕk 2 1
M Ik = R Ik R = hk (B.0.2)
6
Ik ϕk ϕk−1 Ik ϕk1 ϕk 1 2
where hk is the length of the interval Ik . Note that, assembling, the diagonal
elements in the Global mass matrix will be multiplied by 2 (see Example 4.1).
These elements are corresponding to the interior nodes and are the result of adding
their contribution for the intervals in their left and right. The assembling is through
the following Matlab routine:
A Matlab routine to compute the load vector b:
To solve the problem of the L2 -projection, it remains to compute/assemble the
load vector b. To this end we note that b depends on the unknown function f ,
and therefore will be computed by some of numerical integration rules (midpoint,
trapezoidal, Simpson or general quadrature). Below we shall introduce Matlab
routines for these numerical integration methods.
%--------------------------------------------------------------------
% Syntax: b = LoadVector(f, p, phi0, phiN)
% Purpose: To compute load vector b of load f over partition p
% of an interval
% Data: f - right hand side funcion of one variable
% p - vector containing nodes in the partition
% phi0 - if 1: include basis function at the left endpoint
% if 0: do not include a basis function
% phiN - if 1: include basis function at the right endpoint
% if 0: do not include a basis function
%--------------------------------------------------------------------
The data function f can be either inserted as f=@(x) followed by some ex-
pression in the variable x, or more systematically through a separate routine, here
called “Myfunction” as in the following example
y=x.ˆ2
\vskip 0.3cm
Then, we assemble the corresponding load vector, viz:
\begin{verbatim}
b = LoadVector (@Myfunction, p, 1, 1)
Alternatively we may write
f=@(x)x.ˆ2
b = LoadVector(f, p, 1, 1)
function pf = L2Projection(p, f)
The above routine for assembling the load vector uses the Composite trapezoidal
rule of numerical integration. Below we gather examples of the numerical integra-
tion routines:
function M = midpoint(f,a,b,N)
h=(b-a)/N
x=a+h/2:h:b-h/2;
M=0;
for i=1:N
M = M + f(x(i));
end
M=h*M;
function T=trapezoid(f,a,b,N)
h=(b-a)/N;
x=a:h:b;
T = f(a);
for k=2:N
T = T + 2*f(x(k));
end
T = T + f(b);
T = T * h/2;
127
function S = simpson(a,b,N,f)
h=(b-a)/(2*N);
x = a:h:b;
p = 0;
q = 0;
The precomputations for standard and local stiffness and convection matrices:
R R R R −1 1
′ ϕ′ ′ ϕ′ −1 −1
ϕ 0 0 ϕ
I1 0 1 1 1 −1
S I1 = R I1 R = RI1 h h I1 h h
R 11 = h .
′ ′ ′ 1 −1
ϕ
I1 1 0 ϕ I1 ϕ 1 ′ϕ 1 I1 h h I1 h h −1 1
As in the assembling of the mass-matrix, even here, for the global stiffness matrix,
each interior node has contributions from both intervals that the node belongs.
Consequently, assembling we have 2/h as the interior diagonal elements in the
stiffness matrix (rather than 1/h in the single interval computes above). For the
convection matrix C, however, because of the skew-symmetry the contributions
from the two adjacent interior intervals will cancel out:
R R R R h−x 1
′ ′ −1 h−x
ϕ0 ϕ0 I 1 ϕ0 ϕ1
C I1 = R I1 R = RI1 h h R
I1 h h
′ x −1 x1
I 1 ϕ1 ϕ0 I1 ϕ1 ′ϕ1 I1 h h I1 h h
1 −1 1
= .
2 −1 1
A thorough computation of all matrix elements, for both interior and bound-
ary nodes, in the case of continuous piece-wise linear approximation, for Mass-,
stiffness- and convection-matrices are demonstrated in Examples 4.1 and 4.2.
128 APPENDIX B. ALGORITHMS AND MATLAB CODES
%---------------------------------------------------------------------
% Syntax: S = StiffnessMatrix(p, phi0, phiN)
% Purpose: To compute the stiffness matrix S of a partition p of an
% interval
% Data: p - vector containing nodes in the partition
% phi0 - if 1: include basis function at the left endpoint
% if 0: do not include a basis function
% phiN - if 1: include basis function at the right endpoint
% if 0: do not include a basis function
%---------------------------------------------------------------------
%--------------------------------------------------------------------------
% Syntax: C = ConvectionMatrix(p, phi0, phiN)
% Purpose: To compute the convection matrix C of a partition p of an
% interval
% Data: p - vector containing nodes in the partition
% phi0 - if 1: include a basis function at the left endpoint
% if 0: do not include a basis function
% phiN - if 1: include a basis function at the right endpoint
% if 0: do not include a basis function
%--------------------------------------------------------------------------
Finally, below we gather the Matlab routines for finite difference approxima-
tions (also cG(1) and dG(0) ) for the time discretizations.
% Forward Euler:
U_v = U_explicit_E(n); % U_v = U_{n-1}
U_h = (1-dt*a(t_l))*U_v+dt*f(t_l); % U_h = U_{n};
U_explicit_E(n+1) = U_h;
% Backward Euler:
U_v = U_implicit_E(n); % U_v = U_{n-1}
131
% Crank-Nicolson:
U_v = U_CN(n); % U_v = U_{n-1}
U_h = ((1 - dt/2*a(t_l))*U_v + dt/2*(f(t_l)+f(t_r))) ...
/ (1 + dt/2*a(t_r)); % U_h = U_{n}
U_CN(n+1) = U_h;
timevector(n+1) = t_r;
t_l = t_r; % right end-point in the current time interval
% becomes the left end-point in the next time interval.
n = n + 1;
end
figure(1)
if (exactexists)
% if known, plot also the exact solution
u_exact = u(timevector);
plot(timevector, real(u_exact), ’g’)
end
xlabel(’t’)
legend(’Explicit Euler’, ’Implicit Euler’, ’Crank-Nicolson’, 0)
hold off
if (exactexists)
132 APPENDIX B. ALGORITHMS AND MATLAB CODES
end
return
a= @(t) 1;
f= @(t) 0;
u= @(t) exp(-t)
u_0=1;
T= 1;
dt=0.01;
three_methods (u_0, T, dt, a, f, 1, u)
133
Table of Symbols
(u, v) := u1 v1 + u2 v2 + . . . + uN vN , u, v ∈ RN
(u, v) or hu, vi skalar/inner product Z
(u, v) := u(x)v(x) dx for u, v ∈ L2 (I).
I
Ph f L2 -projection (f, w) = (Ph f, w), ∀w ∈ P q (a, b).
Th (I) a partition of I Th [a, b] : a = x0 < x1 < . . . < xN = b.
πh f interpolant of f πh f (xi ) = f (xi ) in a partition Th of I = [a, b].
F DM Finite Difference Method
FE Forward Euler Forward Euler FDM
BE Backward Euler Backward Euler FDM ⇐⇒ dG(0)
CN Crank-Nicolson Crank-Nicolson FDM ⇐⇒ cG(1)
F EM Finite Element Method/Galerkin Method
cG(1) continuous Galerkin continuous, piecewise linear Galerkin approx
dG(0) discont. Galerkin discontinuous, piecewise constant Galerkin
cG(1)cG(1) continuous Galerkin space time continuous, piecewise linear Galerkin
Ci Interpolation Constant
Cs Stability constant
T OL Error TOLerance
Index
B E
boundary condition 3, 5, 7, 55, 74, Error estimates 7, 33, 59, 95
75, 97, 107, 108 a priori error estimates 79, 93
Dirichlet 21, 53, 58, 59, Interpolation error 35, 51,
60, 61, 96, 100
Neumann 21, 96 F
boundary value problem 3, 6, 8, 13, Finite dimensional spaces 21, 26,
28, 29, 53, 56, 58, 59, 61, 64, 65, 65,
72-7, 78, 81, 95, 96, 99, 106 Finite Element Method V, 7, 9,
Two point bvp 53, 72-75 10, 19, 23, 58, 74, 75, 78,
86, 100, 109, 113
C Continuous Galerkin 58, 64, 87,
Cauchy-Schwarz 17, 61, 63, 97-99 90, 93, 104,
Conservation of energy 106, 107, disontinuous Galerkin 87, 90,
111, 104,
Convection 2, 64, 71, 72, 95,
120, 121, 127-129 G
Convection-diffusion 2, 64, 70, 107, Galerkin Method BVP 21,
113, 114 Gauss quadrature 48
D I
differential equation V, 1-8, 41, 92, Interpolation
93, 98, 107, Lagrange interpolation
ordinary differential equation 1, 9, 37-39, 43,
81, linear interpolation 31, 33, 36,
partial differential equation 1-3, 50,
5, 7 polynomial interpolation 11,
135
136