Mathematical Methods PDF
Mathematical Methods PDF
Martin Stmpfle
Contents
1 Numerical Analysis 5
A Appendix 121
A.1 Greek Letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Bibliography 123
Index 125
5
1 Numerical Analysis
7
Ordinary differential equations are equations where the unknown is a funtion in one vari-
able. Many models from engineering sciences include ordinary differential equations. The
most popular class are multi body systems, where several components are linked together
by rods, springs, dampers, or elastomers. Depending on the constraints we distinguish
between initial and boundary value problems.
8
2.1 Introduction
We briefly discuss the basics of ordinary differential equations. Besides theoretical aspects
we introduce numerical definitions as well.
Ordinary differential equations are equations involving a function and some of its deriva-
tives. Some approaches to find solutions require the equation in such a special form that
the highest derivative is isolated on one side of the equation.
F (t, y, y , y , . . . , y (n) ) = 0
2y + 4t2 y 8y = 0 y = 2t2 y + 4y
The general solution of an ordinary differential equation typically is a set of infinite many
functions. Depending on appropriate additional initial conditions the solution then is
unique.
y = y, y(0) = 2 y(t) = 2 et .
b) Using the set of all solutions from Example 2.1 the initial value problem has the following
unique solution:
For boundary conditions the situation is different. The existence and uniqueness of solu-
10
y(t0 ) = y0 , y(t1 ) = y1
y0
y (t0 )
= y2 , y (t1 )
= y3
t0 t1 t
y (m) (tk ) = yn1
y = y,
y(0) = 1, y ( ) = 1 y(t) = sin t + cos t .
2
b) Using the general solution y(t) = c1 sin t + c2 cos t from Example 2.1 the following boundary
value problem has no solution:
y = y, y(0) = 1, y() = 0 c2 = 1, c2 = 0 .
c) Again using the general solution y(t) = c1 sin t + c2 cos t from Example 2.1 the following
boundary value problem has infinite many solutions:
For first-order ordinary differential equation in explicit form the right-hand side of the
equation states the slopes of the solution curves. Using this information a vector field can
be drawn. Connecting the the small line elements gives the set of all solutions.
11
y =
y
t
1
consists of line elements that are in the direction
of lines through the origin. No line elements are 1 t
defined on the y-axis. So, the solutions are half
lines that end at the origin.
y =
t
y
1
are orthogonal to the line elements of y = yt . No
line elements are defined on the t-axis. Hence, 1 t
the solutions are half circles centered at the ori-
gin.
Ordinary differential equations can be generalized from single equations to systems. Each
model state typically contributes one equation to the system. In general, the equations
are coupled. This means that more than one state is involved in each equation.
12
y1 = f1 (t, y1 , . . . , yn )
y
= f (t, y)
yn = fn (t, y1 , . . . , yn )
If the right-hand side of a system of equations does not depend on the independent
variable t, the system is called autonomous. Then, the change in the states depends only
the states themselves and not on time. Autonomous systems are special systems.
y1 = f1 (y1 , . . . , yn )
y
= f (y)
yn = fn (y1 , . . . , yn )
By introducing new states ordinary differential equation of higher order can be transformed
into first-order systems. This is important, because many numerical methods only deal
with first-order equations.
y1 = x y1 = y2
y2 = x
y2 = y3
x(n) = f (x, x , . . . , x(n1) ) ,
yn1 = x(n2) yn1
= yn
yn = x (n1)
yn = f (y1 , . . . , yn )
13
x 3tx + 5x = sin t
y1 = x y1 = y2
y2 = x y2 = y3
y3 = x y3 = 5y1 + 3ty2 + sin t
Since the differential equation is linear, the system also can be written using matrices:
y1 0 1 0 y1 0
y2 = 0 0 1 y2 + 0 .
y3 5 3t 0 y3 sin t
y1 = x y1 = y2 , y1 (0) = 2
y2 = x y2 = cos(ty1 ) + 4t2 + 6y1 , y2 (0) = 1
y1 = x y1 = y3 , y1 (1) = 0
y2 = z y2 = y4 , y2 (1) = 1
y3 = x y3 = 6y1 y3 y4 + tet , y3 (1) = 4
y4 = z y4 = t + y1 + y2 + y3 + y4 , y4 (1) = 2
14
x + 2 x + 02 = 0 ,
where 0 is the damping constant and 0 > 0 is the angular frequency. Using the new states
y1 = x , y2 = x
the second-order differential equation can be transformed into a linear first-order system:
y1 0 1 y1
=
y2 0 2 y2
2
y1 = f1 (t, y1 , . . . , yn ) y1 = f1 (yn+1 , y1 , . . . , yn )
yn = fn (t, y1 , . . . , yn ) yn = fn (yn+1 , y1 , . . . , yn )
yn+1
= 1
x 3tx + 5x = sin t
y1 = x y1 = y2
y2 = x y2 = y3
y3 = x y3 = 5y1 + 3y2 y4 + sin y4
y4 = t y4 = 1
Note, that the original differential equation is linear, whereas the autonomous system has lost
the property of linearity.
There are different types of solutions. A solution that does not change its state at all is
called an equilibrium solution. Other special solutions are periodic solutions. For periodic
solutions, the system states are repeated again and again.
15
y(t) = y(t + T ) with T > 0 is called a periodic solution. The parameter T denotes
the period.
The phase-plane or phase-space together with some solution curves is called phase
portrait.
16
Finally, we introduce the definition of stability. Stability of a solution in general means that
nearby solutions always converge towards the stable solution. This principle of stability is
especially important for equilibrium solutions.
yk = y(tk ) wk
The error of numerical solutions has two main sources. Firstly, any numerical algorithm
is an approximation scheme. For instance, derivatives can be substituted by difference
formulas. Such discretizations cause truncation errors. Secondly, on computers, numbers
are stored with a fixed number of digits. Any floating-point operation thus causes roundoff
d
errors. As a rule of thumb, there optimal step size is h0 = 10 2 , where d is the number
of digits. On general purpose personal computers, d = 16 and thus h0 = 108 . For many
real-world applications, step sizes between 105 and h = 103 yield solutions that are
sufficiently accurate.
The approximation quality of numerical solutions is a central issue in the context of initial
value problems. The most important error is the global error that describes the difference
between the exact and the numerical solution. In most cases, this global error is very
hard to calculate or estimate. As a substitute, the local error is defined as the difference
between numerical and exact solution in one single step. This local error is much easier
18
to compute.
1
E(t, h) 0 (h 0) t ,
h
E(t, h) = O(hp+1 ) t ,
EG (t, h) 0 (h 0) t .
19
wk+1 = wk + h f (tk , wk )
for k N0 . The increment function is the
slope at the left point of each interval.
To investigate the order of Eulers approach, we discuss the local truncation error. We
insert the exact solution y into Eulers formula and get
E(t, h) = y(t) + hf (t, y(t)) y(t + h) .
Euler exact
Now we use Taylor series expansion and obtain
We discuss the order of the implicit Euler: Inserting the exact solution y into the formula
for the local truncation error yields
E(t, h) = y(t) + hf (t + h, y(t + h)) y(t + h) .
implicit Euler exact
Now, we use Taylor series expansion and obtain
K2 = f (tk + 21 h, wk + 12 h K1 )
wk+1 = wk + h K2
for k N0 . The increment function is the slope at the midpoint of each interval.
To discuss the order of the improved Euler, we insert the exact solution y into the formula
of the local truncation error:
1 1
E(t, h) = y(t) + hf (t + h, y(t + h) + hf (t, y(t))) y(t + h) .
2 2
exact
improved Euler
For simplicity, we now omit the argument (t) for function y and the arguments (t, y(t))
for function f and its derivatives. Again, using Taylor series expansion yields
1
E(t, h) = h (ft + fy (f + O(h))) + O(h2 )))
(y + h (f +
2
1
(y + hy + h2 y + O(h3 )) = O(h3 ) .
2
The derivative of y (t) = f (t, y(t)) with respect to t is obtained by the general chain rule.
Since y = f and y = ft + fy f , the leading expressions disappear.
The formula of the local truncation error has to used to proof the order of Heuns method:
1 1
E(t, h) = y(t) + h ( f (t, y(t)) + f (t + h, y(t) + hf (t, y(t)))) y(t + h) .
2 2
exact
Heun
Again, for simplicity, we now omit the arguments (t) and (t, y(t)). Using Taylor series
expansion yields
1 1
E(t, h) = hf + h (f + h (ft + fy (f + O(h))) + O(h2 )))
(y +
2 2
1 2
(y + hy + h y + O(h3 )) = O(h3 ) .
2
The derivative of y (t) = f (t, y(t)) with respect to t is obtained by the general chain rule.
Since y = f and y = ft + fy f , the leading expressions disappear.
a1
a2 b2,1
a3 b3,1 b3,2
ar br,1 br,2 ... br,r1
c1 c2 ... cr1 cr
stage r 1 2 3 4 5 6 7 8 9
order p 1 2 3 4 4 5 6 6 7
0 0
1 1
2 2
1 1
1 1
0 1 2 2
0
1 1
2 2
1 1 2
1 4 1
6 6 6
Kuttas method
0 0
1 1 1 1
2 2 3 3
1
2
0 1
2
2
3
13 1
1 0 0 1 1 1 1 1
1 2 2 1 1 3 3 1
6 6 6 6 8 8 8 8
E = wk+1 wk+1 .
If E < 1
4
h then accept wk+1 and set the step size to 2h for the next step.
Otherwise accept wk+1 and continue.
The numerical solution (wk+1 ) is used only to control the step size.
0 0
1 1
2 2
1 1
1 1 2 1
2
1
4
1
4
1 1
0 1 2 2
1 4 1 1 1 4
6 6 6 6 6 6
0
1 1
4 4
3 3 9
8 32 32
12
13
1932
2197
7200
2197
7296
2197
1 439
216
8 3680
513
4104
845
1
2
27
8
2 2565
3544 1859
4104
40
11
25
216
0 1408
2565
2197
4104
51
16
135
0 6656
12825
28561
56430
50
9 2
55
for k N0 . The coefficients with a20 + b20 0 and a2m + b2m 0 can be listed in a table:
a0 a1 ... am
b0 b1 ... bm
a0 = a1 = . . . = am2 = 0 , am1 = 1 , am = 1 , bm = 0
Investigating the local truncation error a set of possible method variants can be derived.
The achievable order depends on the number of included old values. Eulers method can
be regarded as a special Adams-Bashforth method. The general approach for m is
Inserting this approach into the local truncation error formula yields
1
hb0 + hb1 h = 0 , h2 b0 h2 = 0 .
2
30
Adams-Bashforth methods
The coefficients of m-step Adams-Bashforth methods together with the order p are:
m am1 am b0 b1 b2 b3 b4 b5 p
1 1 1 1 0 1
2 1 1 12 3
2
0 2
3 1 1 5
12
16
12
23
12
0 3
4 1 1 24
9 37
24
24
59 55
24
0 4
5 1 1 251
720
1274
720
2616
720
2774
720
1901
720
0 5
wk+1 = wk + hf (tk , wk ) .
a0 = a1 = . . . = am2 = 0 , am1 = 1 , am = 1 , bm 0
To get appropriate coefficients bk , the local truncation error is stated with the objective to
cancel out as many leading expressions as possible. As in the explicit case, the achievable
order depends on the number of included old values. The implicit Eulers method is a
special Adams-Moulton method.
Adams-Moulton methods
The coefficients of m-step Adams-Moulton methods together with the order p are:
m am1 am b0 b1 b2 b3 b4 p
1 1 1 0 1 1
1 1 1 1
2
1
2
2
2 1 1 12
1 8
12
5
12
3
3 1 1 1
24
24
5 19
24
9
24
4
4 1 1 720
19 106
720
264
720
646
720
251
720
5
The special case p = 1 is the implicit Eulers method. The special case p = 2 is the
trapezoidal method.
b) Again for m = 1, there is a another Adams-Moulton method. This method is called trape-
zoidal method and has order 2:
1 1
wk+1 = wk + h ( f (tk , wk ) + f (tk+1 , wk+1 )) .
2 2
y = y , C.
Since most real-world models embody friction or damping, the interesting case is Re() < 0.
Applying a one-step method with step size h to this equation generates a recursive formula
of the form
wk+1 = g(h)wk .
for the numerical solution wk . Here, g(z) denotes some complex function with a complex
argument z = h C. If Re() < 0, the exact solution y(t) tends to zero. The numerical
solution wk has the same behavior, if g(z) < 1.
wk+1 = g(h)wk
the region of stability is defined as that part of the complex plane where g is con-
tracting:
G = {z C g(z) < 1} .
Within G and the left-half plane the numerical solution has the same quantitative
behavior as the exact solution.
34
g(z) = ei , 0 < 2 ,
where g results from the one-step method applied to the test differential equation.
wk+1 = wk + h f (tk , wk )
g(z) = 1 + z .
The boundary of the region of stability is defined as g(z) = 1. Since all complex points on the
unit circle are of the form ei , we get
1 + z = ei z = 1 + ei .
With [0, 2] the boundary of the region of stability describes a circle with center 1 and
radius 1. The region of stability lies within the circle.
35
K1 = f (tk , wk ) = wk
K2 = f (tk + 1
2
h, wk + h 12 K1 ) = (1 + 1
2
h) wk
wk+1 = wk + h( 61 wk + 46 (1 + 1
2
h) wk + 16 (1 + h + h2 2 ) wk )
= (1 + h + 1
2
h2 2 + 1
6
h3 3 ) wk .
RK3: Kutta
RK4: Classical Runge-Kutta
In terms of stability, good numerical methods cover a wide range of the left-half plane.
There are a couple of methods that cover the complete left-half plane. Such methods are
called A-stable. They are optimal with respect to stability.
G {z C Re(z) < 0} .
z = 1 ei .
1
= ei
1z
With [0, 2] the boundary of the region of stability describes a circle with center 1 and radius
1. The region of stability lies outside the circle and thus covers the whole left half plane. The
implicit Eulers method is A-stable. This is a big advantage of this approach.
38
2+z ei 1 2 sin
= ei z=2 = i.
2z ei + 1 1 + cos
The last equation results from expanding the fraction with the complex conjugate of the denom-
inator ei + 1 and using the relations
(e ei ) (e + ei ) .
1 i 1 i
sin = , cos =
2i 2
With [0, 2] the boundary of the region of stability is the imaginary axis. The region of
stability lies left to the imaginary axis and thus covers the whole left half plane. The trapezoidal
method is A-stable.
are called the first characteristic polynomial and the second characteristic poly-
nomial of the given multistep method.
39
() = 1 + , () = 1 .
() = 1 + , () = .
y = y , C
with Re() < 0. With this equation, a linear multistep method with step size h reads
m m m
ai wk+i = h bi wk+i (ai zbi )wk+i = 0 ,
i=0 i=0 i=0
where z = h. This is a linear difference equation for the sequence wk . The general
solution of that difference equation is based on the powers k , where are the zeros of
the polynomial
m
p() = (ai zbi )i = 0 .
i=0
Hence, the general solution tends to zero, if all zeros lie within the unit circle.
40
the region of stability is defined as that part of the complex plane where the stability
polynomial p has only zeros within the unit circle:
m
G = {z C p() = (ai zbi )i has only zeros with < 1 } .
i=0
Within G and the left-half plane the numerical solution has the same quantitative
behavior as the exact solution.
The boundary of the region of stability is reached if one zero crosses the unit circle:
= 1 = ei , [0, 2) .
Inserting this value into the characteristic polynomial yields the boundary points
m (ei )
(ai zbi ) = 0 z() =
i
.
i=0 (ei )
Hence, all boundary points z() are obtained by varying in the interval [0, 2).
(ei )
z= , 0 < 2 .
(ei )
1 + ei 1
z= = 2 i .
1
2
+2 e +1
This expression is the same as in Example 2.17. Again, all points z lie on the imaginary axis.
Thus, the trapezoidal method is A-stable.
2.5.3 Stiffness
Stiffness describes the relation between necessary step size and solution smoothness. If
a solution behaves continuous and smooth without sudden changes of the slopes on one
hand and requests quite a small step size on the other hand, such a paradox situation is
called stiff. Stiffness is a matter of performance, not of precision. Stiffness also is a local
matter. A differential equation can behave normal in some region and stiff in another.
42
0.1 1 10 1
(A 1 I)v1 = ( ) v1 = 0, (A 2 I)v2 = ( ) v2 = 0
1 10 1 0.1
with eigenvectors
10 1
v1 = ( ) , v2 = ( ) .
1 10
Since 1 and 2 are very different, the system behaves stiff. In comparison with z1 , the function
z2 contributes almost nothing to the general solution.
43
2.6.1 Summary
Initial value problems can be solved numerically in many different ways. Most popular
methods integrate from the initial point in time to the end point step by step. The
resulting solution is a sequence of approximation points.
MATLAB solvers
MATLAB has a variety of built-in solvers for initial value problems:
solver problem type type of algorithm
ode23 nonstiff explicit Runge-Kutta pair, orders 2 and 3
ode45 nonstiff explicit Runge-Kutta pair, orders 4 and 5 (workhorse!)
ode113 nonstiff explicit linear multistep, orders 1 to 13
ode15s stiff implicit linear multistep, orders 1 to 5
ode15i fully implicit implicit linear multistep, orders 1 to 5
ode23s stiff modified Rosenbrock pair (one-step), orders 2 and 3
ode23t mildly stiff trapeziodal rule (implicit), orders 2 and 3
ode23tb stiff implicit Runge-Kutta-type algorithm, orders 2 and 3
45
g(s) = y(b, s)
(3) Find a root of the function g. Use Newtons method or the secant formula.
y(tk+1 ) y(tk1 )
y (tk ) = + O(h2 )
2h
y(tk+1 ) 2y(tk ) + y(tk1 )
y (tk ) = + O(h2 )
h2
2.8 Applications
2.8.1 Biology
Example 2.23 (Predator-Prey model)
The Lotka-Volterra predator-prey model describes the relation between two populations. One
population behaves as predator the other as prey. The model consists of a two-dimensional
system of first-order differential equations. The 4 parameters are a, b, c, d > 0.
x = ax + bxy
y = cy + dxy
48
x = x x2 rxy
y = y y 2 rxy
1.5
0.5
0 0.5 1 1.5 2
Second, we discuss the case r = 2:
x-nullclines: x = 0 and y = 21 x + 1
2
y-nullclines: y = 0 and y = 2x + 1
Equilibrium solution: (0, 0), (1, 0), (0, 1) and ( 31 , 13 ) (unstable)
0.8
0.6
0.4
0.2
0.2
0.2 0 0.2 0.4 0.6 0.8 1 1.2
49
2.8.2 Mechanics
Example 2.25 (Spring damper oscillator)
Let x denote the deflection of a ball with mass m F(t)
and c and k denote the spring and damper coefficient,
respectively. Let F (t) be an external force. Newtons c
law on the balance of forces states:
mx + kx + cx = F (t) . m
x(t)
Using the new states k
y1 = x, y2 = x
the second-order differential equation can be transformed into a linear first-order system:
y1 0 1 0
1 + 1
y
=
y2
c k F (t)
y2 m
m m
m1 x1 + x1 c1 + (x1 x2 )c2 = 0
m2 x2 + x2 c3 + (x2 x1 )c2 = 0
y1 = x1 , y2 = x2 , y3 = x1 , y4 = x2
this second-order system can be written as a linear first-order system with constant coefficients:
0 0 1 0
y 1
y1
y 1
y2
0 0 0
2
= c +c
c2
y3 1 2
0 0 y3
y4
m1 m1
c2 c2 + c3 y4
0 0
m2 m2
50
2.8.3 Engineering
Example 2.27 (Liquid tank)
The model describes the height of a liquid in a spherical tank. The model consists of a first-order
differential equation. The parameter r > 0 describes the tank radius. The parameter cd denotes
a liquid dependent parameter (water: 0.6). The parameter A describes the hole area.
h =
cd A 2gh
2rh h2
For example we can set r = 1.5 m, cd = 0.6, and A = 0.0152 m2 .
3
2.5
2
h [m]
1.5
0.5
0
0 500 1000 1500 2000 2500
time [s]
51
Source: Mitschke
The model consists of a second-order linear differential equation. The state variables are
z
y=( ) .
z
mz + kz + cz = kh + ch .
y = (
0 1 0
k )y + ( )
mc
m c
m
h+ m
k
h
52
Source: Mitschke
The model consists of a system of three second-order linear differential equations. The differential
equations are
m1 z1 k2 (z2 z1 ) c2 (z2 z1 ) + c1 z1 = c1 h
m2 z2 k3 (z3 z2 ) c3 (z3 z2 ) + k2 (z2 z1 ) + c2 (z2 z1 ) = 0
m3 z3 + k3 (z3 z2 ) + c3 (z3 z2 ) = 0
z1
z2
z1
z z3
z = z2 , y=( )=
z3 z z1
z2
z3
The mass matrix, the right-hand side matrix and the amplification by the road read
m1 0 0 c1 0 0 h1
M = 0 m2 0 , R= 0 0 0 , h= 0 .
0 0 m3 0 0 0 0
k2 k2 0 c1 + c2 c2 0
K = k2 k2 + k3 k3 , C = c2 c2 + c3 c3 .
0 k3 k3 0 c3 c3
M z + K z + Cz = Rh .
y = (
0 E 0
)y + ( ) .
M 1 C M 1 K M 1 Rh
53
2.9 Exercises
Theoretical Exercises
Exercise 2.1
For each ODE that ist given, determine its order, check if it is linear, and check if the given
functions are solutions.
a) y = 2t with y(t) = t2 + c.
t
x2
b) y = 2ty + 1 with y(t) = et
2 2
e dx + et .
0
Exercise 2.2
Consider the ODE
y 3y + 2y = t .
Exercise 2.3
Reformulate each of the following IVPs below into a new IVP which involves a first-order system.
a) y + y et y = sin(3t) with y(0) = 1, y (0) = 2, y (0) = 3.
b) x = xy + t2 + 1 and y = x cos y with x(10) = 4, x (10) = 1 and y(10) = 1.
Exercise 2.4
Suppose we had three different methods M1, M2, and M3 for solving IPVs which had orders 1,
2, and 4, respectively. Suppose also that it is known that for a certain IVP, the constant c of the
global error bound
y(tk ) wk chp , k
Exercise 2.5
Compute the region of stability for the trapezoid method
1 1
wk+1 = wk + h ( f (tk , wk ) + f (tk+1 , wk+1 )) .
2 2
Computational Exercises
Exercise 2.6
Consider the IVP
y = y, y(t0 ) = y0 , y (t0 ) = y0
y = y, y(t0 ) = y0 , y(t1 ) = y1 .
Exercise 2.7
MATLAB: Plot the vector fields of the following ODEs for the range [5, 5] [5, 5]. Describe
the solution curves.
a) y =
y
b) y =
t
c) y = 10
sin t
t y 1 10y
Exercise 2.8
MATLAB: Consider the IVP
y = sin(t2 ), y(0) = 1 .
a) Plot the solution of the IVP for t [0, 5] using the function quad with stepsize 0.01.
b) Which element of the discrete solution vector y(k) gives y(3)?
c) What is the value of y(3)?
55
Exercise 2.9
Consider the simple IVP
y = y, y(0) = 1 .
Exercise 2.10
Consider the test initial value problem
Application-based Exercises
Exercise 2.11
Population model with two competing species: Consider the system
x = x x2 y = y y2
1 1
xy, xy .
2 2
Draw a phase-plane diagram for x 0, y 0 which includes all equilibrium solutions, x- and
y-nullclines along with the exact flow directions on the nullclines and approximate flow directions
in the regions between nullclines.
Exercise 2.12
After a skydiver jumps from an airplane and until the parachute opens, the air resistance is
proportional to v1.5 , and the maximum speed that the skydiver can reach is 130km/h.
a) Set up the differential equation for the vertical velocity. What is the initial condition?
b) MATLAB: Implement the Runge-Kutta method and integrate the system with h = 0.01 for
t [0, 10]. Plot the solution curve and include the curve if there were no air resistance.
c) MATLAB: How many seconds would it take for the skydiver to break a falling speed of
100km/h?
56
Exercise 2.13
The vertical dynamical behavior of a vehicle can be studied using a quarter car with three masses.
this simplified model consists of a wheel with mass m1 , the body with mass m2 , and the driver
with mass m3 . The masses are linked with springs and dampers.
a) Set up three scalar differential equations of order 2 describing the vertical dynamics using the
positions z1 , z2 , and z3 as state variables. Let h denote the road height.
b) Transform the differential equation into a second-order system with mass matrix M , damper
matrix K, and spring matrix C. Use z = (z1 , z2 , z3 )T as state variable.
c) Transform the system into an explicit first-order system. Use y = (z, z)T as state variable.
d) MATLAB: Implement the right-hand side function of the ODE system as set up in c).
e) MATLAB: Implement the road height function. Let x denote the road position. Then,
0 if x 4
h(x) = 0.2 if 4 < x 12
0 if 12 < x
m1 = 10 , m2 = 100 , m3 = 30
Simulate the quarter car using the built-in solver ode45. Plot the curves z1 (t), z2 (t), z3 (t),
and h(t).
g) MATLAB: Change the parameters mi , ki , and ci and discuss the behavior.
h) MATLAB: Implement the classical RK4 method. Compare the simulation results with this
method and the built-in ode45 method.
i) MATLAB: Animate the model and study the oscillations.
Exercise 2.14
When lighting a match, the ball of flame grows rapidly until it reaches a critical size. Then it
remains at that size because the amount of oxygen being consumed by the combustion in the
interior of the ball balances the amount available through the surface. The simple model with y
representing the radius of the ball is
y = y2 y3 ,
2
y(0) = , t [0, ] .
a) Show that y(t) = 1 is a steady state solution.
b) MATLAB: Integrate the IVP with the MATLAB routine ode45 using = 0.01. Set the relative
error to 104 .
c) MATLAB: Integrate the IVP with the MATLAB routines ode45 and ode23s using = 0.0001.
Set the relative error to 104 . Compare the number of steps needed. Zoom into the second
half of the graph.
57
Partial differential equations are used as mathematical models in a vast range of technical
applications. Heat distributions, diffusion processes and wave dynamics can be described
with partial differential equations. Any kind of fluid dynamics is mathematically expressed
by the famous Navier-Stokes equations.
58
3.1 Introduction
First of all, we briefly discuss the most important basics on partial differential equations.
The independent variables typically describe time and space. It is common to denote
problems in one spacial variable as 1D problems. Likewise, problems in two or three
spacial variables are called 2D and 3D problems.
Dimension
Partial differential equations are called
1D problems if only one spacial variable is involved,
2D problems if two spacial variable are involved,
3D problems if three spacial variable are involved.
u = 0, u = uxx + uyy = 0 .
Solutions of the Laplace equation are called harmonic. Conversely, any function with
u = 0 solves the Laplace equation.
c) The function u(x, t) = e t (c1 e + c2 e
2
x x
) also is a solution of the heat equation for
any coefficients c1 and c2 .
2 3
ux = 2xy, uxx = 2y, uy = x2 y , uyy = 2y 2 .
3
2x 2y 2x2 + 2y 2 2x2 2y 2
u = + = + 2 =0.
x x + y
2 2 y x + y
2 2 (x + y )
2 2 2 (x + y 2 )2
Many important partial differential equations are linear and of second order:
In general, the coefficients a, b, c and d1 , d2 , d3 depend on (x, y). The factors 2 simplify
some equations related to this quadratic form. Using differentials we can rewrite the
equation as
a b x
( d1 u = f .
)
x y
, + 2 ( , ) ( ) + d
x y d 2
3
b c
y
A
Finding the zeros of the characteristical polynomial of matrix A
det (A I) = 2 (a + c) + (ac b2 ) = 0
is called
elliptic if b2 ac < 0,
parabolic if b2 ac = 0,
hyperbolic if b2 ac > 0.
In general, the coefficients a, b, c and d1 , d2 , d3 depend on (x, y). Hence, the type of
equation depends on (x, y).
62
and with that b2 ac = 1 < 0. Hence, the 2D Laplace equation is of second-order, linear,
and elliptic.
b) In terms of classification, the 1D heat equation gives
ut = uxx a = , b = 0, c=0
which yields b2 ac = 0. Hence, the 1D heat equation is of second-order, linear, and parabolic.
c) For the 1D wave equation we find
utt = 2 uxx a = 2 , b = 0, c = 1
and with that b2 ac = 2 > 0. Hence, the 1D wave equation is of second-order, linear, and
hyperbolic.
This gives b2 ac = y. Hence, the Tricomi equation is elliptic, if y > 0, parabolic if y = 0, and
hyperbolic if y < 0.
As with ordinary differential equations partial differential equations typically have infinite
many solutions. To define a well-posed problem with a unique solution, additional initial
and boundary conditions are necessary.
63
define a unique solution. Here, arg(x, y) denotes the angle between the vector (x, y)T and
the positive x-axis.
c) Consider the 2D Laplace equation on the triangle D = {(x, y) x, y 0, x + y 1}. With
u(x, y, 0) = e(x +y 2 )
2
, u(1, y) = u(1, y) = u(x, 1) = 0, u(x, 1) = 1
u(x) ui = u(xi ) wi
u(x, y) ui,j = u(xi , yj ) wi,j
For the continuous solution x [a, b], y [c, d], and t 0. The discretized solution is
defined for i = 0, 1, . . . , n, j = 0, 1, . . . , m, and k N0 . If the points are equidistant with
h > 0 and t > 0 then xi = a + hi, yj = c + hj, and tk = t k. Numerical approximations
of u are denoted by w.
If the problem is 2D or higher, all grid nodes can be ordered linearly in a vector. One of
the possible variants to do this is to use the reading or alphabetical order. All grid nodes
are ordered with ascending index values. The first index has highest and the last index
lowest priority.
66
The grid consists of 21 11 = 231 nodes with 19 9 = 171 inner nodes and 20 + 10 + 20 + 10 = 60
boundary nodes. If the solution function is, for example, w(x, y) = xy 2 , the vector
f (t + h) f (t)
f (t + h) = f (t) + h f (t) + O(h2 ) f (t) = + O(h) .
h
In the same way, the backward difference formula reads
f (t) f (t h)
f (t h) = f (t) h f (t) + O(h2 ) f (t) = + O(h) .
h
Both approximations are of first order O(h). Subtracting the second from the first ex-
panded polynomial
h2 h3
f (t + h) = f (t) + h f (t) + f (t) + f (t) + O(h4 )
2 6
h2 h3
f (t h) = f (t) h f (t) + f (t) f (t) + O(h4 )
2 6
yields the central formula for the first derivative
f (t + h) f (t h)
f (t) = + O(h2 )
2h
which is of second order O(h2 ).
68
These finite differences in one dimension now can be applied to a function u depending on
x and y. Using these differences, approximations w of u are involved only at grid points.
In this context, we assume a regular grid with equidistant points.
Finite differences
The second-order partial derivatives of a function u(x, y) at point xi , yj can be ap-
proximated using h > 0 by the numerical values
wi+1,j 2wi,j + wi1,j
uxx (xi , yj ) (wxx )i,j =
h2
wi,j+1 2wi,j + wi,j1
uyy (xi , yj ) (wyy )i,j =
h2
69
The equations for all numerical values wi,j can be collected in a linear system Aw = b.
If the domain is rectangular, the system matrix A has a special structure, it consists of
5 diagonals. Using a grid with n + 1 nodes in both directions, the vector w consists of
(n + 1)2 elements in reading order and the matrix A has (n + 1)4 elements!
70
4 1 1 0
1
1
A=
1
,
b=
.
1
1 1 4 0
This linear system is valid for all inner nodes wi,j . Boundary conditions for boundary
nodes have to be added separately. Using the reading order in a retangular grid with
n + 1 nodes in x-direction and m + 1 nodes in y-direction, the values 1 are separated
by m 1 zero elements.
Since all finite differences used in the numerical solution scheme are of order 2, the 5-
point-star is of second-order. This is sufficient and gives reasonable precision for normal,
well-conditioned problems.
Until now, the linear system Aw = b is valid only for inner nodes. Nodes on the boundary
typically have only 2 or 3 neighbors within the domain. Thus, the 5-point-star is not
applicable.
Ghost nodes
Applying the 5-point-star to boundary nodes y
ghost nodes
generates ghost nodes outside the domain. ym
These ghost nodes are eliminated again with
modified difference formulas. Thus, for bound-
ary nodes the 5-point-star changes into formu-
las involving less than 5 nodes. y0
x0 xn x
To include Dirichlet boundary conditions there are two alternatives. The first alternative is
to keep the boundary nodes in the linear system and replace the corresponding 5-point-star
equations by trivial equations.
71
ak,` = 0, ` k, ak,k = 1, bk = gk .
are introduced.
1 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 10
0
0 0 0 1 0 0 0 0 0
A= 0 1 0 1 4 1 0 1 0 , b= 0 .
0 0 0 0 0 1 0 0 0 10
0
0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 1 10
The second alternative is to delete all boundary node equations from the linear system. As
an advantage, this implies a smaller matrix A. However, matrix A is then less structured.
This may be regarded as a disadvantage.
72
Since the values of the boundary nodes are known through the Dirichlet conditions, we set up a
linear system resulting from the 5-point-star including only the inner nodes:
4w11 w21 = 5 4 1 0 0 0 5
4w21 w11 w31 = 5 1 4 1 0 0 5
4w31 w21 w32 = 5 0 1 4 1 0 w = 5 .
4w32 w31 w33 = 0 0 0 1 4 1 0
4w33 w32 = 0 0 0 0 1 4 0
4 1 0 0 0 0
0 15 4 0 0 25
0 0 56 15 0 100
0 0 0 209 56 100
0 0 0 0 780 100
w1,1 1.7949, w2,1 2.1795, w3,1 1.9231, w3,2 0.5128, w3,3 0.1282 .
To include Neumann boundary conditions there are at least two approaches. In a first
approach we could use forward or backward difference formulas for the boundary nodes.
The advantage is that these formulas do not include nodes outside the domain. The big
disadvantage however is that their order is only O(h). This order does not match with
the second-order differences O(h2 ) of the 5-point-star for the inner nodes. A second
approach makes use of temporary ghost nodes outside the domain. If wn,j is a boundary
node on the right part of a boundary, the ghost node wn+1,j lies outside the domain. Let
u
(xn , yj ) = gn,j
n
be the value of the normal derivate at the boundary node. Then, using the central
difference formula in x-direction for the normal derivative gives the approximation
wn+1,j wn1,j
= gn,j wn+1,j = 2h gn,j + wn1,j .
2h
73
ak,` = 2, bk = 2h gk .
The coefficients , , and are chosen such that the resulting local discretisation error
is as small as possible. One possible choice defines the 9-point-star.
It can be shown that the 9-point-star is of higher order than the 5-point-star. To be more
precise, the order is O(h4 ) in comparison with O(h2 ). However, 9 neighboring points are
74
involved in each equation. The corresponding matrix has more non-zero elements than
the 5-point-star matrix.
1 2
t
A= , = .
h2
1 2
This linear system is valid for all inner nodes wi,k+1 with 1 i n 1 and k 0.
Boundary conditions for boundary nodes have to be added separately.
75
1 0 0 0 0
1 1
0 0 0
2 2
wk+1 = A wk with A= 0 1
0 1
0 .
2 2
1
0 0 1
0
0 0
2
0 0 1
2
has to be computed. The first and last row in A are due to the Dirichlet boundary conditions.
Starting with the initial condition, the first iterates and the limit interate read
0 0 0 0 0
0 0 0 1.25 2.5
w0 = 0 , w1 = 0 , w2 = 2.5 , w3 = 2.5 , . . . , w = 5 .
0 5 5 6.25 7.5
10 10 10 10 10
The simple and straightforward explicit method is of order O(h2 ) and only of order O(t).
Moreover, a stability conditon can be derived. This condition is obtained by investigating
the eigenvalues of matrix A.
stability is not guaranteed. Using the explicit method, in each interation step
1 0 0 0 0
1 1 1 0 0
wk+1 = A wk with A= 0 1 1 1 0 .
0 0 1 1 1
0 0 0 0 1
has to be computed. The first and last row in A are due to the Dirichlet boundary conditions.
Starting with the initial condition, the first iterates read
0 0 0 0 0
0 0 0 10 20
w0 = 0 , w1 = 0 , w2 = 10 , w3 = 10 , w4 = 40 , . . .
0 10 0 20 20
10 10 10 10 10
This numerical solution shows increasing oscillations and thus do not behave similiar to the real
solution.
Instead of using the forward difference formula for the time discretisation the backward
one can be used as well. The 4-point-star then is established in such a way that just 1
node lies on the old time level and 3 nodes lie on the new one.
In this implicit approach the matrix times vector multiplication from the explicit method
changes into the solution of a linear system. This implies that the computational effort
increases for the implicit variant.
1 + 2
t
B= , = .
h2
1 + 2
This linear system is valid for all inner nodes wi,k+1 with 1 i n 1 and k 0.
Boundary conditions for boundary nodes have to be added separately.
The implicit method is still quite simple and also of order O(h2 ) and only of order O(t).
But in contrast to the explicit approach, the implicit variant is unconditionally stable. This
is a major advantage.
1 0 0 0 0
1 3 1 0 0
B wk+1 = wk with B= 0 1 3 1 0 .
0 0 1 3 1
0 0 0 0 1
The first and last row in B are due to the Dirichlet boundary conditions. Starting with the initial
condition, the iterates read
0 0 0 0
0 0.476 1.043 2.5
w0 = 0 , w1 1.428 , w2 2.653 , . . . , w = 5 .
0 3.809 5.487 7.5
10 10 10 10
Likewise, with t = 1
2
the corresponding linear system reads
11 0 0 0 0
2 2 12 0 0
B wk+1 = wk with B= 0 12 2 21 .
0
1
0 0 12 2 2
0 0 0 0 1
0 0 0 0
0 0.178 0.471 2.5
w0 = 0 , w1 0.714 , w2 1.530 , . . . , w = 5 .
0 2.678 4.221 7.5
10 10 10 10
When making a comparison between the results obtained with the two values of t we have to
be careful. Only every second iterate obtained with t = 21 corresponds to an iterate obtained
with t = 1.
Now, we combine explicit and implicit approach. The two 4-point-stars merge into one
6-point-star called Crank-Nicolson method. This method has been published in a paper
in 1947.
79
Like in the implicit case the Crank-Nicolson method requires the solution of a linear system
in each iteration step. Note, that for 1D parabolic equations the size of the resulting linear
system is comparable to that of 1D elliptic equations and thus in general much smaller
than the size of 2D elliptic equations.
2 2 2 + 2
A= , B= .
2 2 2 + 2
This linear system is valid for all inner nodes wi,k+1 with 1 i n 1 and k 0.
Boundary conditions for boundary nodes have to be added separately.
The Crank-Nicolson method is in several ways satisfying. Firstly, the method is of second-
order for h as well as for t. Secondly, the method is unconditionally stable. There is no
restriction regarding the time step size t.
B wk+1 = A wk . 5 w0
2.5
With t = 1 the corresponding matrices are
1 2 3 4 5 6 x
1 0 0 0 0 1 0 0 0 0
1 0 1 0 0 1 4 1 0 0
A= 0 1 0 1 0 , B= 0 1 4 1 0 .
0 0 1 0 1 0 0 1 4 1
0 0 0 0 1 0 0 0 0 1
The first and last row in B are due to the Dirichlet boundary conditions. Starting with the initial
condition, the iterates read
0 0 0 0
0 0.357 1.173 2.5
w0 = 0 , w1 1.428 , w2 3.265 , . . . , w = 5 .
0 5.357 6.173 7.5
10 10 10 10
Likewise, with t = 1
2
the corresponding matrices are
1 0 0 0 0 11 0 0 0 0
2 12
1 1
1 0 0 3 0 0
2 2
A= 0 1
1 1
0 , B= 0 12 3 21 0 .
2 2
1 1
0 0 1
1 0 0 12 3 2
0 0
2
0 0 1
2
0 0 0 0 1
0 0 0 0
0 0.098 0.407 2.5
w0 = 0 , w1 0.588 , w2 1.660 , . . . , w = 5 .
0 3.431 4.852 7.5
10 10 10 10
When making a comparison between the results obtained with the two values of t we have to
be careful. Only every second iterate obtained with t = 21 corresponds to an iterate obtained
with t = 1.
81
The explicit variant result in a molecule with 6 points. The time update is calculated by
the multiplication of a matrix with a vector. Using n + 1 nodes in x-direction and m + 1
nodes in y-direction, the update matrix A consists of (n + 1)2 (m + 1)2 elements.
1 4
t
A= , =
.
h2
1 4
This linear system is valid for all inner nodes wi,j,k+1 with 1 i n1 and 1 j m1
and k 0. Boundary conditions for boundary nodes have to be added separately.
The order of the explicit approach is the same in 1D and 2D. To ensure stability of the
numerical solution, the coefficient has to be below the value 14 . This value in 2D is
different to the value 21 in 1D.
82
Swapping the difference formulas of time layers k and k + 1 yields the implicit variant.
Here, the backward difference formula with respect to time is applied. This results again
in a 6-point-star.
A single node of time k + 1 is computed from several nodes of time k. This again implies
the solution of a linear system. In contrast to elliptic problems, auch a linear system has
to be solved in each time step.
83
1 + 4
t
B=
,
= .
h2
1 + 4
This linear system is valid for all inner nodes wi,j,k+1 with 1 i n1 and 1 j m1
and k 0. Boundary conditions for boundary nodes have to be added separately.
The order of simple explicit and implicit methods is O(h2 ) and O(t). Thus, the implicit
variant has no advantage in terms of precision. But, concerning the overall behavior of
the numerical solution, there is no limit of t. Even with large t, the numerical solution
behaves in the same way as the exact solution.
A further improvement is obtained, using the average of the explicit and the implicit
method. In this approach, 10 points in total are included in the methods molecule. 5
points refer to time k and another 5 points refer to time k + 1.
The time update involves two matrices. One matrix is multiplied with wk+1 , the other
one with wk . Hence, a matrix multiplication and the solution of a linear system have to
be calculated.
2 4 2 + 4
A=
, B =
.
2 4 2 + 4
This linear system is valid for all inner nodes wi,j,k+1 with 1 i n1 and 1 j m1
and k 0. Boundary conditions for boundary nodes have to be added separately. Using
the reading order in a retangular grid with n + 1 nodes in x-direction and m + 1 nodes
in y-direction the values and are separated by m 1 zero elements.
It can be shown, that the order of the Crank-Nicolson approach is 2 for h as well as for
t. Moreover, the advantage of unconditional stbility of the implicit method is inherited
to the Crank-Nicolson method. These advantages make the Crank-Nicolson approach to
a commonly used solver for parabolic problems.
In general, the discretization of space and time is different. This implies a coefficient ,
that also depends on the factor of the differential equation. Moreover, three time layers
are included in the hyperbolic 5-point-star.
2 2
t
2
A= , = 2 .
h2
2 2
This linear system is valid for all inner nodes wi,k+1 with 1 i n 1 and k 1.
Boundary conditions for boundary nodes have to be added separately. In addition, a
special initial step is necessary for k = 0.
Since the central difference formula is used for time discretization in the hyperbolic 5-
point-star, this approach is of second order with respect to space and time. The Courant-
Friedrichs-Levy condition describes the limit of stability.
ghost nodes for the seed computation in the first step are used:
wi,1 wi,1
= gi wi,1 = wi,1 2 t gi .
2 t
Inserting this formula into the hyperbolic 5-point-star yields
can be computed using the central difference formula in t-direction with ghost nodes
wi,1 outside the domain:
wi,1 = (1 )gi + (gi1 + gi+1 ) + t gi , 1in1.
2
This method is of order O(t2 ) .
Finally, one can compare the parts of boundary that influence the exact and the numerical
solution. To ensure stability, the numerically used boundary region has to be superset of
the analytical relevant region.
x
87
x0 = a = 2, x1 = 2.5, x2 = 3.5, x3 = 5, x4 = b = 6 .
ba
xk = a + h k, h= , k = 0, 1, 2, . . . , n
n
which yields for n = 40 the nodes
88
2 2.5 2
1 1.5 1 2 3 T1 T2
1 3 4 n2 n3 n4
2 1.5 T3
T5
x= , y = 1.5 , T = 2 3 5 . 1
3 3 T4 T6
0.5 5 6 n5 n7
1
3 4 6 n6
2 0.5 4
0.5 6 7 1 2 3 4 x
3
The process of decomposing a 2D domain is quite different from that for a 1D interval.
Finding good triangulations is an art in some sense. The Delaunay triangulation is such
that the smallest angle in any triangle is as large as possible. This ensures numerical
stability during the calculation of the finite element solution.
min max
Tk
Delaunay
The Delaunay triangulation has the property
that no other node lies in the circumcircle of
any triangle.
90
1 1
0 0 1
1 0
2 0
x = , y= ,
3 1
1 2 3 x
1 3
0 2
0 1
In each row of T the node indices are arranged starting with the smallest index and then continuing
counterclockwise. Finite elements are well suited for curved shaped domains. Hence, for a quarter
circle domain, the finite element method is advantageous in comparison with the finite difference
method.
Lu = f .
91
d2
Lu = f, L= .
d x2
b) In 2D, the Poisson equation uxx + uyy = f (x, y) can be written with an operator:
2 2
Lu = f, L = = 2 = + .
x2 y 2
Sometimes, the equation is multiplied by 1, yielding
Lu = f, L = , f = f .
defines an inner product. Symmetry, linearity, and positive definiteness result directly form
the corresponding properties of the integral.
b) Likewise, the integral of the product of two functions u and v on a 2D domain D
u, v = u(x, y) v(x, y) d x d y
D
is an inner product.
d) In the same way, using the gradients of two functions u and v on a 2D domain D
u, v = u(x, y) v(x, y) d x d y
D
defines an inner product. Note that the function within the integral is real-valued.
Lu, v = u, v .
For the negative Laplace operator Lu = u the inner product with a function v is defined
as
Lu, v = u, v = u v dx dy .
D
Here again, the first expression vanishes. Second, we proof positive definiteness:
b b
u (x) u(x) d x = u (x) u(x) + (u (x))2 d x > 0
b
Lu, u =
a a a
for any function u 0 with u(a) = u(b) = 0. From this, we can understand that for positive
definiteness it is necessary to use the negative of the original Laplace operator.
b) In 2D, the negative Laplace operator is also symmetric and positive definite for functions
that are zero on the boundary D. Starting with
u
Here, denotes the derivative with respect to the normal direction n on the boundary of
n
the domain. With v = 0 on D again the first expression vanishes. Likewise, starting with
u, Lv = u(x, y) v(x, y) d x d y
D
With u = 0 on D we finally get symmetry. Positive definiteness can be seen starting with
One of the key ideas of the finite element approach is to rewrite the original partial
differential equation as a variational or an optimization problem. The strong formulation
95
Lu = f .
The theorem is fundamental. Hence, it is worth to proof the equality between the three
formulations.
a) (A) (B)
Take the inner product on both sides of the equation Lu = f with an arbitrary
function v.
b) (B) (A)
The opposite direction follows immediately with the fundamental lemma of the cal-
culus of variations: If Lu f, v = 0 for any function v then Lu f has to be the
zero function.
c) (B) (C)
Let v be an arbitrary function. Then, with w = v u we get
1
F (v) = F (u + w) = L(u + w), u + w f, u + w .
2
Applying the linearity of L and the inner product, the functional F (v) reads
1
F (v) = (Lu, u + Lu, w + Lw, u + Lw, w) (f, u + f, w) .
2
Since L is assumed to be symmetric, the second and third inner product are the
same:
1 1
F (v) = Lu, u f, u + Lu, w f, w + Lw, w .
2 2
F (u) 0 0
96
() = Lu, v + Lv, v f, v .
0 = (0) = Lu, v f, v .
u =f.
Using again the negative Laplace operator Lu = u in combination with the function
f = f the main theorem specializes to the following:
(A) The original partial differential equation yields the Poisson equation:
Lu = f u = f u =f .
(B) The original principle of virtual work can be written as the following equation:
Lu, v = f, v u, v = f, v u, v = f, v .
97
Hence, for the Laplace or Poisson equation the principle of virtual work and the potential
energy functional can be formulated with gradients.
Function spaces
A solution u with u = 0 on D of a partial differential equation on a domain D can be
searched for in the following function spaces S S S :
The function space with strong differentiability conditions on u
S = {u D R u C 2 (D)} .
S = {u D R u C(D), u C 1 piecewise on D} .
Similar to 1D, in 2D hat functions also have a very small support. They look like a
carneval hat or a pyramid.
is used for the unknown function u. Likewise, the arbitrary function v is one after the
other replaced by the hat functions 1 , . . . , n . In this way, n equations are obtained.
99
Lu, v = f, v
is used for the function v. As a necessary condition the gradient of the functional is set
to zero. Like in the Galerkin approach, here also n equations are obtained.
Now we focus on Rayleigh-Ritzs approach for the Poisson equation. In the following, we
100
1 n n n
F (c1 , . . . , cn ) = cj ck j , k + cj f, j .
2 j=1 k=1 j=1
1 n
F (c1 , . . . , cn ) = 2 cj i , j + 2ci i , i + f, i .
ci 2 ji
The first two expressions can be collected in one sum, and then the partial derivative is
set to zero:
n
F (c1 , . . . , cn ) = cj i , j + f, i = 0 .
ci j=1
ai,j = i , j , bi = f, i , i, j = 1, . . . , n .
The functions 1 , . . . , n are the basis functions and f is the right-hand side of the
Poisson equation on the domain D.
Using the stiffness matrix and the load vector the Rayleigh-Ritz method for the Poisson
equation finally can be written as a linear system: Ac = b.
The next step addresses the question how the stiffness matrix can be computed. Calcu-
lating the elements ai,j one after the other in two nested loops is straightforward but not
efficient, because same integrals are computed several times.
Assembly
The stiffness matrix A and the load vector b can be assembled
nodewise: Each value ai,j and bi is computed separately. This approach is time-
consuming since same parts of the integrals are computed several times.
elementwise: The integrals are computed locally on each mesh element Tk . This
approach generates element stiffness matrices Ak and element load vectors bk .
102
i, j {k1 , k2 , k3 } .
This means, that for each triangle, 9 integrals contributing to the stiffness matrix have to
be computed. These 9 values define the element stiffness matrix.
The functions k1 , k2 , and k3 are the basis functions corresponding to the nodes
k1 , k2 , and k3 of triangle Tk .
In the same way, only if i {k1 , k2 , k3 } we obtain a non-zero entry in the load vector.
Thus, 3 integrals contribute to the element load vector.
The functions k1 , k2 , and k3 are the basis functions corresponding to the nodes
k1 , k2 , and k3 of triangle Tk . The function f is the right-hand side of the Poisson
equation.
Now we address to the computation of the element stiffness matrix. We calculate the 9
103
(k)
values ai,j simultaneously. Let
xk1 xk2 xk 3
nk 1 = ( ), nk2 = ( ), nk3 = ( )
yk1 yk2 yk3
be the coordiantes of the three nodes of triangle Tk . On one hand, the numerical solution
w on Tk is a linear combination of the three relevant hat functions:
w(x, y) = ck1 k1 (x, y) + ck2 k2 (x, y) + ck3 k3 (x, y) .
The transposed gradient of w can be written as a matrix vector product:
T w(x, y) = ck1 T k1 (x, y) + ck2 T k2 (x, y) + ck3 T k3 (x, y)
ck1
= (T k1 (x, y), T k2 (x, y), T k3 (x, y)) ck2 .
ck3
k1 1
Ak = k2 (T k1 , T k2 , T k3 ) 1 dx dy = B Tk B k dk
k3 T k 2
xk1 xk 2 xk3
( ), ( ), ( )
yk1 yk2 yk3
1 22 21 12 1 0 1 1
B1 = ( )= ( ) .
2 02 10 21 2 2 1 1
1 20 01 12 1 2 1 1
B2 = ( )= ( ) .
2 00 10 01 2 0 1 1
1 0 1 1 1 2 1 1
B3 = ( ) , B4 = ( ) .
2 2 1 1 2 0 1 1
When calculating B 4 we have to be careful about the not ascending order of the node indices:
1, 5, 2. This means k1 = 1, k2 = 5, and k3 = 2. Using the formula Ak = 12 dk B Tk B k , in this
example we obtain 4 equal stiffness matrices:
1 1
1
2
A1 = A2 = A3 = A4 = 1 1 0 .
2
1 0 1
Note the special structure of the element stiffness matrices. The diagonal elements are positive.
The sum in each row and column is zero.
106
1 22 21 12 0 0.4 0.4
B1 = ( )=( ) .
2.5 0 2.5 10 2.5 1 1 0.4 0.6
1 20 01 12 1 0.5 0.5
B2 = ( )=( ) .
2 00 10 01 0 0.5 0.5
We also show how the matrix with the gradients of triangle T3 is computed:
1 00 01 10 0 0.4 0.4
B3 = ( )=( ) .
2.5 2.5 0 1 2.5 01 1 0.6 0.4
1 00 02 20 0 0.667 0.667
B5 = ( )=( ) .
3 4 2.5 2.5 4 2.5 2.5 0.5 0.5 0
In matrices B k and Ak , some numbers are truncated to 3 digits after the decimal point.
107
d1 = 1, d2 = 1, d3 = 1, d4 = 1, d5 = 1, d6 = 1.
Since the orientation of the triangle nodes is not the same we obtain positive and negative values.
The absolute value is constant because the triangulation is regular and all triangles have the same
area. The matrices B k read
1 0 1 1 1 0 1 0 1
B1 = B4 = B6 = ( ) , B2 = ( ) , B3 = B5 = ( ).
0 1 1 0 1 1 1 1 0
The equality of some of the matrices B k is reflected in the element stiffness matrices. The first
two different matrices are
1 1
1 1
1 0 1 0
A1 = A4 = A6 = 0 1 1 , A2 = 1 2 1 ,
2 2
1 1 2 0 1 1
1 1
1
2
A3 = A5 = 1 1 0 .
2
1 0 1
108
Since all triangle nodes are in counterclockwise order, all values dk are positive. The matrix
consisting of the gradients of triangle T1 reads
1 21 1 3 32 1 1 3 32
B1 = ( )=( ) ,
1 00 10 01 0 1 1
and the last two matrices are similar to the first two matrices:
1 1 0 1 1 1 0
B6 = ( ) , B7 = ( ) .
31 31 1 3 0 32 1 3 1
1 0.5 0.5
A3 = A4 = A5 = 0.5 0.5 0
0.5 0 0.5
In the same way the element load vector can be calculated. Since the function f of the
Poisson equation in general is nonlinear, the resulting integrals have to be computed using
numerical integration methods. We do not discuss this issue here.
k1
k2
,
k3
k1 k2 k3
2 1 1 0 0 4 1 2 1 0
1 1
1 1
1 0 0 0 1 0 0 0
1 0 1 0 0 2 0 2 0 0 .
2
0
2
1
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0
Next, matrix A3 is added. Due to the non-ascending node order we have to add A4 carefully:
6 1 2 2 1 8 2 2 2 2
1 2
1 1
1 0 0 0 2 0 0 0
2 0 2 0 0 2 0 2 0 0 .
2
2
2 0 0 2 0 2 0 0 2 0
1 0 0 0 1 2 0 0 0 2
4 1 1 1 1
1 1 0 0 0
A= 1 0 1 0 0 .
1 0 0 1 0
1 0 0 0 1
110
1 0 1 0 0 0 0 2 0 2 0 0 0 0
0 1 1 0 0 0 0 0 1 1 0 0 0 0
1 1 2 0 0 0 0 2 1 4 1 0 0 0
1
0
1
0
.
1
2 2
0 0 0 0 0 0 0 1 0 0 0
0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
2 0 2 0 0 0 0 2 0 2 0 0 0 0
0 3 2 0 1 0 0 0 3 2 0 1 0 0
2 2 5 1 0 0 0 2 2 6 1 0 1 0
1
0
1
0
.
1 1
2 2
0 1 0 0 0 0 1 0 0 0
0 1 0 1 1
0 0 1 0 0 0 0 2 0
0 0 0 0 0 0 0 0 0 1 0 1 2 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
2 0 2 0 0 0 0 2 0 2 0 0 0 0
0 3 2 0 1 0 0 0 3 2 0 1 0 0
2 2 8 2 0 2 0 2 2 8 2 0 2 0
1
0
1
0
.
2 2 1
2 2
0 2 0 0 0 0 3 0 0
0 1 1 0 1 1
0 0 2 0 0 0 2 0
0 0 2 0 1 3 0 0 0 2 0 1 4 1
0 0 0 0 0 0 0 0 0 0 1 0 1 2
1 0 1 0 0 0 0
0 1.5 1 0 0.5 0 0
1 1 4 1 0 1 0
A=
0 0 1 1.5 0 0 0.5 .
0 0.5 0.5
0 0 1 0
0 0 1 0 0.5 2 0.5
0 0 0 0.5 0 0.5 1
112
For the Laplace equation the load vector b up to now is just a zero vector. A nonzero
numerical solution is obtained if boundary conditions are added. As in the finite difference
approach, here we also impress the given boundary conditions on the linear system Ac = b.
ak,` = 0, ` k, ak,k = 1, bk = gk .
4 1 1 1 1 c1 0
0 1 0 0 0 c2 g2
0 0 1 0 0 c3 = g3 .
0 0 0 1 0 c4 g4
0 0 0 0 1 c5 g5
Hence, the value of the unknown inner node w1 is just the average of the boundary nodes:
1
w1 = (g2 + g3 + g4 + g5 ) .
4
113
Hence, the value of the unknown inner node w1 is a weighted average of the 4 adjacent boundary
nodes. Boundary value g6 is not relevant for w1 .
Now we have discussed the complete procedure of deriving the overall linear system that
results from the finite element approach using Rayleigh-Ritzs method with hat functions
for the Laplace equation.
Ritzs method with hat functions for Laplace equation with Dirichlet boundary
The finite element solution using Rayleigh-Ritzs method with hat functions k on a
mesh with n nodes and m elements for the 2D Laplace equation with Dirichlet boundary
can be computed as follows:
(1) Initialize the stiffness matrix A Rnn and the load vector b Rn to 0.
(2) Compute the element stiffness matrices Ak and add them to A for k = 1, . . . , m.
(3) Impress Dirichlet boundary conditions on A and b.
(4) Solve the linear system Ac = b. The numerical solution is
n
w(x, y) = cj j (x, y) .
j=1
114
3.4 Applications
3.4.1 Heat Distribution
Example 3.41 (Steady-state heat distribution on a square metal plate)
Consider the 2D Laplace equation uxx + uyy = 0 on y
the given domain D with Dirichlet boundary condi- 10
tions on the outer boundary 8
2 4 6 8 10 12 x
115
3.5 Exercises
Theoretical Exercises
Exercise 3.1
Show that the function
ux + uy 2u = 0 .
Exercise 3.2
Consider Laplaces differential equation
uxx + uyy = 0 .
a) For which constant c is the function u = x3 + cxy 2 a solution of the differential equation?
b) Show that u = ln (x a)2 + (y b)2 solves the differential equation.
Exercise 3.3
State the type of the following linear second-order PDEs. If the type changes for different
values of the independent variables, indicate precisely how the type varies with the independent
variables.
a) uxy = ux b) (x2 1)uxx + 2xyuxy + (y 2 1)uyy = xux + yuy
Exercise 3.4
Show that the local truncation error for the Crank-Nicolson method for the heat equation ut =
uxx is O(t2 ) + O(x2 ) provided that the solution is sufficiently differentiable.
117
Computational Exercises
Exercise 3.5
Consider the 2D-Laplace equation
uxx + uyy = 0, 0 x, y 1
a) Set up a grid over the domain using the step size h = 0.25 . Introduce the nodes wi,j
u(xi , yj ) for 0 i, j 4 (including boundary nodes).
b) Discretize the problem using the 5-point stencil for the PDE and the central difference formula
for the Neumann boundaries.
c) Transform the 2D nodes w0,0 to w4,4 into a 1D node vector w using the reading order. Set
up the matrix A R2525 and the vector b R25 for the linear system Aw = b.
Exercise 3.6
Consider the 2D Laplace equation
uxx + uyy = 0, 0 x, y 3
a) Discretize the problem using the 5-point-star with the grid size h = 1.
b) Set up a linear system Aw = b with A R44 and b R4 for the 4 inner nodes.
c) Solve the linear system Aw = b.
d) Triangulate the squares in the grid by lines from left down to right up.
e) Solve the problem with finite element approach. Use Ritzs method with 2D hat functions.
f) Compare the finite difference solution with the finite element solution.
118
Exercise 3.7
Consider the 2D Laplace equation y
uxx + uyy = 0, 0 x, y 2
2
with Dirichlet boundary conditions
a) Set up the stiffness matrix and the load vector of the linear system Ac = b using Ritzs method
with 2D hat functions.
b) Solve the linear system Ac = b.
Exercise 3.8
Consider the 2D Laplace equation y
uxx + uyy = 0
2
with Dirichlet boundary conditions
a) Set up the stiffness matrix and the load vector of the linear system Ac = b using Ritzs method
with 2D hat functions.
b) Solve the linear system Ac = b.
119
Application-based Exercises
Exercise 3.9
Consider the 2D-Laplace equation u = uxx + uyy = 0
y
on the following domain with the Dirichlet boundary 10
conditions on the outer boundary
8
u(x, 10) = 100, u(x, 0) = u(0, y) = u(10, y) = 0 6
and with the Dirichlet boundary conditions on the inner 4
boundary (hole) 2
u(x, 7) = 100, u(x, 3) = u(3, y) = u(7, y) = 0 .
2 4 6 8 10 12 x
a) Set up the finite difference method for the steady-state heat problem for the Laplace equation
with Dirichlet boundary conditions using a common step size h = 1.
b) MATLAB: Solve the resulting linear system and give a surface plot of the solution.
c) MATLAB: Give a corresponding isotherm plot.
d) Repeat parts a) through c) using the step size h = 0.5.
Exercise 3.10
Consider the 2D-Laplace equation u = uxx + uyy = 0
y
on the following domain D with the Dirichlet boundary 10
conditions on the upper boundary
8
u(x, 8) = 100 6
and with zero Dirichlet boundary conditions on the rest 4
of the boundary 2
u(x, y) = 0, (x, y) D, y8
2 4 6 8 10 12 x
a) Set up the finite difference method for the steady-state heat problem for the Laplace equation
with Dirichlet boundary conditions using the common step sizes h = 1 and h = 0.5.
b) MATLAB: Solve the resulting linear system and give a surface plot of the solution.
120
Exercise 3.11
Consider the 2D-Laplace equation u = uxx + uyy = 0
y
on the following domain D with the Dirichlet boundary 10
conditions on the outer boundary
8
u(x, 10) = 100, u(x, 0) = u(0, y) = u(10, y) = 0 6
and with the Dirichlet boundary conditions on the inner 4
boundary (hole) 2
u(x, 7) = 100, u(x, 3) = u(3, y) = u(7, y) = 0 .
2 4 6 8 10 12 x
The initial conditions are
u(x, y) = 0, (x, y) D D .
a) Set up the 2D Crank-Nicolson method for the time-dependent heat problem. Use h = 0.5
and t = 0.1 for t [0, 5].
b) MATLAB: Solve the resulting linear system and give a surface plot animation of the solution.
c) Set up the explicit difference method for the above problem and compare the resulting linear
system of equations with the Crank-Nicolson scheme.
d) MATLAB: Implement the explicit difference method and compute the solution for t = 0.05
and t = 1.5. Compare the solutions.
Exercise 3.12
Consider the 2D-Laplace problem
y
10
u = uxx + uyy = 0
8
with the Dirichlet conditions
6
u=2 , (x 5)2 + (y 5)2 = 22
4
u = cos(2) , (x 5)2 + (y 5)2 = 52
2
on the given domain.
2 4 6 8 10 12 x
a) MATLAB: Generate approximately n approximately equally spaced nodes within the domain.
Choose a method that respects the symmetry of the domain, and therefore use nodes on
circles with radii between the inner and the outer boundary circle.
b) MATLAB: Generate a triangulation of the domain. Introduce a temporary ghost node to
delete triangles outside the domain.
c) MATLAB: Set up the stiffness matrix and the load vector for the given equation. Impress the
boundary conditions in a final step.
d) MATLAB: Solve the problem and plot a graph of the solution.
e) MATLAB: Vary the number of nodes n.
121
A Appendix
A.1 Greek Letters
Bibliography
[Hairer] Hairer, Nrsett, Wanner: Solving Ordinary Differential Equations I, II, Springer
[Huebner] Huebner, Dewhirst, Smith, Byrom: The Finite Element Method for Engineers,
Wiley
Vehicle Dynamics
[Genta] Genta: Motor Vehicle Dynamics: Modeling and Simulation, World Scientific
Mathematics
[Koch/Stmpfle] Koch, J., Stmpfle, M.: Mathematik fr das Ingenieurstudium, 2nd edition,
Carl Hanser Verlag, Mnchen, 2012
Formularies
Index
B F
backward difference formula 44 finite difference method 27
boundary condition 9 flow line 9
constant 42 forward difference formula 44
costant 42
Dirichlet 41
initial 42 G
natural 41 f. Galerkins method 57
Neumann 41 general Runge-Kutta method 16
periodic 42 global truncation error 12
boundary conditions 41 f.
boundary value problem 9 H
hat function 57
C heat equation 41
central difference formula 44 Heuns method 15
classical Runge-Kutta method 16 hyperbolic 40
consistent 12 hyperbolic 5-point-star 52
constant boundary condition 42
convergent 12
126
I periodic solution 10
implicit 4-point-star 47 phase portrait 10
implicit 6-point-star 50 phase-plane 10
implicit Eulers method 13 phase-space 10
implicit form 8 Poisson equation 41
improved Eulers method 14 positive definite 55
increment function 14, 20 positive definite differential operator 55
initial boundary condition 42 predictor corrector methods 22
initial condition 8
initial value problem 8 R
inner product 55 Rayleigh-Ritzs method 58
linear 55 reading order 43
positive definite 55 region of stability 23
symmetric 55 roundoff error 11
Runge-Kutta-Fehlberg method 19
L
Laplace equation 41 S
line element 9 shooting method 26
linear 8, 40, 55 stable 11
linear m-step method 20 step size control 18
linear multistep method 20 stiff 25
load vector 59 stiffness matrix 59
local truncation error 12 symmetric 55
symmetric differential operator 55
M system of ordinary differential equations 9
matrix,
element stiffness 60 T
stiffness 59 triangulation 54
mesh 54 Delaunay 54
multistep method 20 truncation error 11
N U
natural boundary condition 41 f. unstable 11
Neumann boundary condition 41
node 54
nullcline 11 V
vector,
element load 60
O load 59
one-step method 14 vector field 9
order 12
ordinary differential equation 8
W
wave equation 42
P
parabolic 40
partial differential equation 40
partition 54
periodic boundary condition 42