Lecture Notes Numerical Analysis
Lecture Notes Numerical Analysis
Jonas Tölle1
Intended learning outcomes. A!er the course, the student will be able to…
explain the fundamental concepts of numerical analysis, like condi"on number, stability, and convergence rate;
construct the floa"ng point numbers;
discuss and employ basic numerical algorithms like Newton’s method;
use the Monte-Carlo method in basic problems in analysis and geometry;
apply different methods of interpola"on polynomials and numerical quadrature rules;
understand the Euler scheme and linear mul"-step methods for solving ordinary differen"al equa"ons.
Floa!ng-point numbers
The set of real numbers R is infinite in two ways: it is unbounded and con"nuous. In most prac"cal compu"ng, the second
kind of infiniteness is more consequen"al than the first kind, so we turn our a$en"on there first.
Instead of R, we shall introduce the set of floa!ng-point numbers (floats) F. They come with different bases, precisions and
exponent ranges, and other features. The basic representa"on is
x = ±(d0 .d1 d2 … dp )k ⋅ k e .
k ∈ N ∖ {1} is called base or radix, p ∈ N0 := N ∪ {0} is called the precision, di , i ∈ {0, … , p}, and the sequence of
numbers
p
(d0 .d1 d2 … dp )k := ∑ di k −i
i=0
If k= 2, we have binary floats. In the binary case, we observe that we can always choose d0 = 1, hence saving one bit, which
can be expressed by e. We refer to this as normaliza!on. The man"ssa is always contained in the interval [1, 2).
(1.b1 b2 )2
5
2 2
3
1 5 3
2 8 4
Rounding
It holds that round(x) = x(1 + δ), where ∣δ∣ < 2ε , where ε denotes the machine epsilon. Note that usually δ depends on x.
There is a way to define the standard arithme"c opera"ons on F such that
a ⊕ b = round(a + b) = (a + b)(1 + δ1 ),
a ⊖ b = round(a − b) = (a − b)(1 + δ2 ),
a ⊗ b = round(ab) = ab(1 + δ3 ),
a a
a ⊘ b = round ( ) = (1 + δ4 ), b
= 0.
b b
Here, generally δi
= δj , i
= j.
k = 2, 64 bits, where:
… …
Thus, there are two zeros, two infini"es and NaN which denotes “not a number”. The smallest posi"ve normalized number is:
Here’s an easy-to-follow video explaining floa"ng point numbers (and a specific version of Newton’s algorithm).
Condi!oning of problems
∣y − y^∣ ≈ C(x)∣x − x
^∣.
∣ y − y^ ∣ ∣x − x
^∣
≈ K(x)
∣ y ∣ ∣ x ∣
By the normaliza"on, we guarantee that
Now,
f (x) − f (x
^)
y − y^ = f (x) − f (x
^) = (x − x
^)
x−x ^
→f ′ (x) as x
^→x
−^ ( ) − ( ^) f (x) − f (x
^) −^
y − y^ f (x) − f (x
^) f (x) − f (x
^) x − x
^ x
= =
y f (x) x−x ^ x f (x)
→f ′ (x) as x
^→x
∣ xf ′ (x) ∣
Thus, K(x) = .
∣ f (x) ∣
Example. f (x) = 2x, f ′ (x) = 2. Thus, C(x) = 2, K(x) = ∣∣ 2x ∣ = 1. This is a well-condi"oned problem.
2x ∣
Stability of algorithms
Defini!on. An algorithm or numerical process is called stable if small changes in the input produce small changes in the output.
It is called unstable if large changes in the output are produced by small changes in the input.
An algorithm is stable, if every step is well-condi"oned (i.e. has a uniformly bounded condi"on number). It is unstable if any
step is ill-condi"oned (i.e. the condi"on number may become arbitrarily large).
Example.
Set:
ε2
∣fl(x + y) − (x + y)∣ ≤ (∣x∣ + ∣y∣) (ε + ).
4
≤ .
∣ x+y ∣ ∣x + y∣
BEA:
2
Thus the rela"ve error for each term is less or equal to ε + ε4 .
Hence the sum of two floa"ng point numbers is backwards stable.
Well-condi"oned problems may have unstable algorithms. For stability, each step has to be well condi"oned. Some ill-
condi"oned steps produce an unstable algorithm. Ill-condi"oned problems cannot be reliably solved with a stable algorithm.
Example. Consider evalua"ng f (x) = 1 + x − 1 for x close to zero. The rela"ve condi"on number is:
∣ xf ′ (x) ∣ x
K(x) = =
∣ f (x) ∣ 2 1 + x( 1 + x − 1)
x( 1 + x + 1) 1+x+1
= = ,
2 1 + x( 1 + x − 1)( 1 + x + 1) 2 1+x
and K(0) = 1.
Consider the following 3 steps;
1. t1 := 1 + x, well-condi"oned, x close to 0.
2. t2 := t1 , rela"vely well-condi"oned, also absolutely well condi"oned, because t1 is close to 1.
∣ 2 ∣
3. t3 := t2 − 1, ill-condi"oned, rela"ve condi"on number of this step: K3 (t2 ) = t t−1 , which becomes unbounded
∣2 ∣
for t2 close to 1!
On the other hand, the problem is well-condi"oned. Solve it by wri"ng:
( 1 + x + 1)( 1 + x − 1) x
f (x) = 1+x−1= = ,
1+x+1 1+x+1
Numerical differen!a!on
What is that ξ (= “xi”)? Under certain assump"ons elementary func"ons have their series expansions. If the series is
truncated, we have the Taylor polynomial. However, the residual has an explicit expression but due to applica"on of an
intermediate value theorem, the exact loca"on of the point ξ is not known, i.e. “generic”.
Let (xk ) be an infinite sequence of real numbers. Let sk := supl≥k xl , k ∈ N, be the supremum (i.e., the lowest upper bound)
of the tail (that is, large indices l ≥ k ) of (xk ). Define the lim sup (limes superior) as
Other than a limit, it always exists, but can be ±∞. If (xk ) is bounded, the lim sup is the largest limit of a converging
subsequence. If limk→∞ xk ∈ (−∞, ∞) exists, then limk→∞ xk = lim supk→∞ xk . The opposite is not true.
Assume that limk→∞ xk = x and that there exists some large index M ∈ N such that xk
= x for all k ≥ M . Then we
define the following quan"ty for p ≥0
∣xk+1 − x∣
C(p) := lim sup .
k→∞ ∣xk − x∣p
∣xk+1 − x∣ ∣xk+1 − x∣
C(p) = lim sup = lim sup [ ∗ ∣xk − x∣
p∗ −p
]
k→∞ ∣xk − x∣p
k→∞ ∣xk − x∣p
) = C(p∗ ) ⋅ {
∣xk+1 − x∣ 0 if p < p∗ ,
≤ (lim sup ∗ ) ⋅ (lim sup ∣xk − x∣
p∗ −p
k→∞ ∣xk − x∣p
k→∞ ∞ if p > p∗ .
⎧0 if 0 ≤ p < p∗ ,
C(p) = ⎨C(p∗ ) if p = p∗ ,
⎩∞ if p > p∗ .
The number p∗ is called order of convergence for the sequence (xk ) and determines the rate of convergence as follows:
When working with convergence es"mates it is o!en useful to use the following approxima"on:
∗
∣xk+1 − x∣ ≈ C∣xk − x∣p
log(∣xk+1 − x∣) ≈ log (C∣xk − x∣p ) = log(C) + log (∣xk − x∣p ) = log(C) + p∗ log(∣xk − x∣).
∗ ∗
The rate of convergence can be used interchangeably with the order of convergence. However, there is some cau"on
necessary, as different authors use different terminology here. Usually, the order of convergence always refers to the same
thing, namely, the p∗ -exponent in the denominator of the limit defining the order of convergence. Most confusingly, some
authors call the order of convergence “rate of convergence”, as e.g. here. The English Wikipedia ar"cle calls it the order of
convergence, whereas here the rate of convergence is the constant in the defini"on, which also determines the speed of
convergence, together with the order of convergence. So, please always check the context, as the use of the terminology
should be clear from it. If there is no defini"on, try to figure out what is meant in each text. As a rule of thumb: The “order
of convergence” is a unique terminology in numerical analysis. The “rate of convergence” can mean at least two different
things. I will use both words for the same thing, but will try to make clear what I mean from case to case. In any case, to be
sure, use “order of convergence”. My PhD advisor usually said that in mathema"cs “it’s all hollow words” (meaning that one
should check the defini"on).
The Landau nota"on is an amazing tool applicable in all of real analysis. The reason it is so convenient and widely used is
because it underlines a key principle of real analysis, namely ‘‘es"ma"on’’. Loosely speaking, the Landau nota"on introduces
two operators which can be called the “order of magnitude” operators, which essen"ally compare the magnitude of two given
func"ons.
The “li#le-o”
The “li$le-o” provides a func"on that is of lower order of magnitude than a given func"on, that is the func"on o(g(x)) is of a
lower order than the func"on g(x). Formally,
Defini!on.
Let A ⊆ R and let c ∈ R.
Let f , g : A → R.
f (x)
If limx→c g(x) = 0 then we say that
Examples.
The “Big-O ”
The “Big-O ” provides a func"on that is at most the same order as that of a given func"on, that is the func"on O(g(x)) is at
most the same order as the func"on g(x). Formally,
Defini!on.
Let A ⊆ R and let c ∈ R
Let f , g :A→R
∣ f (x) ∣
If there exists M > 0 such that limx→c < M then we say that
∣ g(x) ∣
"As x → c, f (x) = O(g(x))"
Examples.
As x → 0, sin x = O(x);
As x → π2 , sin x = O(1).
Applica!ons
We will now consider few examples which demonstrate the power of this nota"on.
Differen!ability
Let f : U ⊆ R → R and x0 ∈ U .
Taylor’s Theorem
Let f : R → R be con"nuous. We are interested in methods for finding zeros, that is, roots of f , in other words, x ∈ R, such
that f (x) = 0.
Bisec!on method
The intermediate value theorem for con"nuous func"ons implies that x1 < x < x2 with f (x) = 0 exists if f (x1 )f (x2 ) < 0
, i.e., there is a sign change. The bisec!on method is based on halving the interval such that the sign condi"on is preserved. Note
that, in principle, we have to look for intervals [x1 , x2 ].
Let us analyze the convergence rate. Let [a, b] be an interval. A!er k steps the interval of analysis has length b−a
2k
which
converges to zero for k → ∞. Let us look in a neighborhood of radius δ > 0, so that
b−a b−a b−a
≤ 2δ ⇔ 2k+1 ≥ ⇔ k ≥ log2 ( ) − 1.
2k δ δ
Every step reduces the error by factor 12 . The convergence rate is thus linear.
Newton’s method
1
Assume that f ∈ C 1 . For an ini"al value x0 , consider the itera"on
f (xk )
xk+1 = xk − k = 0, 1, … .
f ′ (xk )
(x∗ − x0 )2 ′′
0 = f (x∗ ) = f (x0 ) + (x∗ − x0 )f ′ (x0 ) + f (ξ)
2
Theorem. If f ∈ C 2 and x0 is sufficiently good (i.e. close to the root x∗ ) and if f ′ (x∗ )
= 0, then Newton’s method converges
quadra"cally.
for some ξk ∈ [x∗ , xk ]. Take xk+1 from the method and subtract,
f ′′ (ξk )
2
xk+1 − x∗ = (x∗ − xk ) .
2f ′ (xk )
≤D
In other words,
∣xk+1 − x∗ ∣ ≤ D∣xk − x∗ ∣2 ,
as k → ∞ and thus xk → x∗ .
Hence the method is quadra"c. Note that f ′ (xk ) does not vanish by con"nuity if xk is close to x∗ . □
′
What happens if f (x∗ ) = 0?
f ′′ (ξk )
xk+1 − x∗ = (x∗ − xk )2
2f ′ (xk )
→0
as k → ∞.
By Taylor’s expansion (η =“eta”):
′
f ′ (xk ) = f (x∗ ) + (xk − x∗ )f ′′ (ηk ) = (xk − x∗ )f ′′ (ηk )
=0
Secant method
′
Some"mes it can be difficult or computa"onally expensive to compute the deriva"ve f (xk ). Newton 's method can be
adapted by approxima"ng the deriva"ve by the differen"al quo"ent. The secant method is the following two-step recursive
algorithm.
1+ 5
with two dis"nct star"ng points x0
= x1 . The convergence rate is 2 ≈ 1.62, the golden ra!o.
We could for instance use Newton’s method to find fixed points by se%ng f (x) := φ(x) − x.
Banach’s Fixed Point Theorem. Suppose that φ is a contrac!on, that is, there exists a constant L < 1 such that
∈ R. Then there exists a unique fixed point x∗ ∈ R of φ, i.e., φ(x∗ ) = x∗ , and the fixed point itera"on φn :=
for all x, y
φ ∘ … ∘ φ sa"sfies limn→∞ φn (x0 ) = x∗ for any star"ng point x0 ∈ R. The convergence rate is at least linear.
n-times
Furthermore,
1 − Lk−j
∣xk − xj ∣ ≤ Lj ∣x1 − x0 ∣.
1−L
as N → ∞, which proves that {xk } is a Cauchy sequence. The linear convergence rate follows also from this es"mate.
The existence of a fixed point follows from the con"nuity of φ (as contrac"ons are uniformly con"nuous, in fact, even Lipschitz
con"nuous) as follows.
Theorem. Assume that φ ∈ C p for p ≥ 1. Furthermore, assume that has a fixed point x∗ and assume that
for p ≥ 2 and
G′ (x∗ ) < 1
= 1. Then the fixed point sequence {φk (x0 )} converges to x∗ at least with rate p, provided that the star"ng point x0 is
if p
sufficiently close to x∗ . If, in addi"on, φ(p) (x∗ )
= 0, then the rate of convergence is precisely p.
Proof. First note that by Banach’s fixed point theorem the limit indeed converges to x∗ for suitable star"ng points x0 . By the
Taylor expansion,
p−1
φ(l) (x∗ ) G(p) (ξk )
xk+1 − x∗ = φ(xk ) − φ(x∗ ) = ∑ (xk − x∗ )l + (xk − x∗ )p
l=1
l! p!
for some ξk between x∗ and xk . The sum will be le! empty for the case p = 1. Since φ(l) (x∗ ) = 0 for 1 ≤ l ≤ p − 1, we
get that
∣φ(p) (ξk )∣
∣xk+1 − x∗ ∣ = ∣xk − x∗ ∣p
p!
.
By con"nuity, there exists C > 0 (with C < 1 for p = 1) such that
∣φ(p) (ξk )∣
≤C
p!
for ξk sufficiently close to x∗ (that is, for sufficiently large k ). Thus,
∣xk+1 − x∗ ∣ ≤ C∣xk − x∗ ∣p
for large k , and thus the rate of convergence is at least p. Note that for p = 1, this also proves convergence by
If φ(p)
= 0, then by con"nuity, there exists K > 0 such that
∣φ(p) (ξk )∣
≥K
p!
∣xk+1 − x∗ ∣ ≥ K∣xk − x∗ ∣p
which implies that the rate of convergence cannot be higher than p. Thus the rate of convergence is precisely p. □
Note. From the above proof, we expect that close to the fixed point x∗
∣φ(p) (x∗ )∣
∣xk+1 − x∗ ∣ ≈ ∣xk − x∗ ∣p ,
p!
when
Polynomial interpola!on
Idea. Approximate a func"on f : R → R over [a, b] by a polynomial p such that in dis!nct data points (xi , yi ), i =
0, 1, … , n, the approxima"on is exact, that is,
Note. Interpola"on polynomials are not per se unique, for instance the data {(−1, 1), (1, 1)} can be interpolated by
p(x) = 1, q(x) = x2 , or r(x) = x4 − x2 + 1. However, we will see later that p is the unique interpola"on polynomial
with deg p ≤ 1 = n.
Example. (1, 2), (2, 3), (3, 6), as data set {(xi , yi ) : i = 0, 1, 2} on the interval [1, 3].
2
We are looking for a polynomial p2 (x) = ∑j=0 cj xj , which is chosen to be 2nd order, because we have 3 data points and 3
unknown coefficients.
We can formulate the problem in matrix form:
⎛1 x0 x20 ⎞
det 1 x1 x21 = ∏(xj − xi )
= 0,
⎝1 x2 x22 ⎠ i<j
⎛1 1 1⎞ ⎛c0 ⎞ ⎛2⎞
1 2 4 ⋅ c1 = 3 .
⎝1 3 9⎠ ⎝c2 ⎠ ⎝6⎠
p2 (x) = x2 − 2x + 3.
The computa"onal complexity of solving the linear system is O(n3 ). We used the natural basis for the polynomials.
What would be the ideal basis?
Defini!on. (Lagrange basis polynomials) Suppose that xi
= xj if i
= j . We call
n
x − xj
ϕi (x) := ∏
xi − xj
j=0
i=j
the ith Lagrange basis polynomial.
The Lagrange interpola!on polynomial is given by
n
p(x) := ∑ yi φi (x).
i=0
Clearly,
φi (xj ) = δi,j := {
1 if i = j,
0 if i
= j.
(x − 2)(x − 3)
φ0 (x) =
(1 − 2)(1 − 3)
(x − 1)(x − 3)
φ1 (x) =
(2 − 1)(2 − 3)
(x − 1)(x − 2)
φ2 (x) =
(3 − 1)(3 − 2)
Newton’s interpola!on
n−1
1, x − x0 , (x − x0 )(x − x1 ), …, ∏(x − xj ).
j=0
n−1
pn (x) = a0 + a1 (x − x0 ) + … + an ∏(x − xj )
j=0
p(x0 ) = y0 ⇒ a0 = y0 ,
and
y1 − a0
p(x1 ) = a0 + a1 (x1 − x0 ) = y1 ⇒ a1 = .
x1 − x0
⎛1 0 ⋯ ⎞⎛ ⎞ ⎛ ⎞
⎛1 0 ⋯ ⎞ ⎛ a0 ⎞ ⎛ y0 ⎞
1 x1 − x0 0 ⋯ a1 y1
1 x1 − x0 (x2 − x0 )(x2 − x1 ) 0 ⋯ a2 = y2 .
⋮ ⋮ ⋮ ⋮ ⋮ ⋮
⎝1 x1 − x0 (x2 − x0 )(x2 − x1 ) ⋯ ∏n−1 (x − x ) ⎠ ⎝an ⎠ ⎝yn ⎠
j=0 n j
Example.
p2 (x) = a0 + a1 (x − 1) + a2 (x − 1)(x − 2)
⎛1 0 0⎞ ⎛a0 ⎞ ⎛2⎞
1 1 0 ⋅ a1 = 3
⎝1 2 2⎠ ⎝a2 ⎠ ⎝6⎠
Uniqueness
Theorem. Interpola"on polynomials with n + 1 nodes xi , i = 0, 1, … , n are unique in the class of polynomials q with
deg q ≤ n.
Proof. (Idea). pn has at most n roots. Let pn and qn be two interpola"ng polynomials for the same set of data. Then
Hence pn − qn has n + 1 dis"nct roots. As deg(pn − qn ) ≤ max(deg pn , deg qn ) = n, the only polynomial with n + 1
roots is the polynomial which is constantly zero. Hence,
pn = qn .
We have used the corollary to the fundamental theorem of algebra which states that every non-constant real polynomial of
degree m has at most m zeros. □
Divided differences
n=1
p(x) = a0 + a1 (x1 − x0 ) + a2 (x − x2 )(x − x1 ) + … + an ∏(x − xj ).
j=0
Defini!on. The divided difference of order k , denoted by f [x0 , x1 , … , xk ], is defined as the ak -coefficient of the Newton
interpola"on polynomial with data yi = f (xi ), in other words,
f [x0 , x1 , … , xk ] := ak .
Theorem.
yj − yi
y − yi = (x − xi ).
xj − xi
Proof. (Idea). We have three interpola"on polynomials p, q , r , where deg p = k , deg q = deg r = k − 1. p interpolates at
x0 , x1 , … , xk , q interpolates at x0 , x1 , … , xk−1 , and r interpolates at x1 , … , xk .
Claim.
x − x0
p(x) = q(x) + (r(x) − q(x)).
xk − x0
=0 for xi
x0 : p(x0 ) = q(x0 ) = f0 .
x1 , … , xk−1 : p(xi ) = q(xi ).
xk − x0
xk : p(xk ) = q(xk ) + (r(xk ) − q(xk ) = r(xk ).
xk − x0
=1
The highest order term has the coefficient
r(k−1) q (k−1)
where rk−1 = f [x1 , x2 , … , xk ] = (k−1)! and qk−1 = f [x0 , x2 , … , xk−1 ] = (k−1)! ,
which can be proved by the general Leibniz rule. □
Interpola!on error
Assume that f ∈ C n+1 . We are interested in the local (pointwise) error (residual)
where
n
w(x) = ∏(x − xj )
j=0
and
f (x′ ) − p(x′ )
c= .
w(x′ )
We find that
h(xi ) = 0 for i = 0, 1, … n.
Furthermore,
f (x′ ) − p(x′ )
h(x′ ) = f (x′ ) − p(x′ ) − w(x′ ) = 0.
w(x′ )
Hence h has n + 2 dis"nct zeros. By Rolle’s theorem (see Differen"al and Integral Calculus 1), h(n+1) will have at least one
zero. Let’s call this point ξ .
h(n+1) (x) = f (n+1) − p(n+1) (x) − cw(n+1) (x) = f (n+1) (x) − c(n + 1)!
=0
Hence
and thus
f (n+1) (ξ)
c= .
(n + 1)!
1
f [x0 , x1 , … , xn , x] = f (n+1) (ξ(x)),
(n + 1)!
which follows from the formula for R, R(n+1) = f (n+1) and R(xi ) = f (xi ) for i = 0, 1, … , n.
Piecewise interpola!on
b−a
h :=
n
Idea. Approximate the func"on on each subinterval using some low order interpola"on polynomial such that the interpola"on
func"on is exact at the nodes.
x−x x−x
x − xi x − xi−1
ℓi (x) = f (xi−1 ) + f (xi ) , x ∈ [xi−1 , xi ].
xi−1 − xi xi − xi−1
f (n+1) (ξ) n
By the residual formula on each subinterval R(x) = (n+1)!
∏j=0 (x − xj ), we get the interpola"on error
f ′′ (ξ)
f (x) − ℓi (x) = (x − xi−1 )(x − xi ),
2!
h2
∣f (x) − ℓi (x)∣ ≤ M , x ∈ [xi−1 , xi ].
8
Note. If f ′′ is bounded over the whole interval [a, b] then the error is the same over the whole interval.
Hermite interpola!on
3
Piecewise interpola"on by degree 3 polynomials p3 (x) = ∑j=0 cj xj . As we have 4 coefficients, we need 4 constraints. We
demand that not only the func"on but also the deriva"ves are exact at the nodes. Let p be a cubic interpola"on polynomial on
[xi−1 , xi ]. Then p′ is a quadra"c polynomial. Recall that h = xi − xi−1 .
We have the condi"ons:
1. p(xi−1 ) = f (xi−1 ),
2. p(xi ) = f (xi ),
′ ′
3. p (xi−1 ) = f (xi−1 ),
′ ′
4. p (xi ) = f (xi ).
Set
x − xi x − xi−1
p′ (x) = f ′ (xi−1 ) + f ′ (xi ) + α(x − xi−1 )(x − xi ).
xi−1 − xi xi − xi−1
Integra"ng yields
f ′ (xi−1 ) x f ′ (xi ) x x
p(x) = − ∫ (t − xi ) dt + ∫ (t − xi−1 ) dt + α ∫ (t − xi−1 )(t − xi ) dt + C.
h xi−1 h xi−1 xi−1
Plugging in xi−1 for x yields that C = f (xi−1 ). Plugging in xi for x and integra"ng yields
3 ′ 6
α= 3
(f (xi−1 ) + f ′ (xi )) + 3 (f (xi−1 ) − f (xi )).
h h
Splines
This requires a global setup. All coefficients are defined first, only evalua"on is piecewise.
Setup. Let h = xi − xi−1 be constant. Define
zi := s′′ (xi ), i = 1, … , n − 1.
Now,
1 1
s′′ (x) = zi−1 (xi − x) + zi (x − xi−1 ).
h h
where
and
1 h2
Ci = [fi − fi−1 + (zi−1 − zi )] .
h 6
Now s has been defined over all subintervals. However, the zi are s"ll unknown!
Using the condi"on for con"nuity of the deriva"ves s′i (xi ) = s′i+1 (xi ) for all i yields
1 h2 1 h2
zi + [(fi − fi−1 ) + (zi−1 − zi )] = − zi + [(fi+1 − fi ) + (zi − zi+1 )] ,
h h
2 h 6 2 h 6
for i = 1, … , n − 1.
In fact, this cons"tutes a triangular system:
2h h h 1
zi + zi−1 + zi+1 = (fi+1 − 2fi + fi−1 ) =: bi .
3 6 6 h
The values z0 and zn at the interval boundary have to be moved to the right hand side, and thus:
1 h
b1 := (f2 − 2f1 + f0 ) − z0
h 6
and
1 h
bn−1 := (fn − 2fn−1 + fn−2 ) − zn .
h 6
z0 and zn can be chosen freely, for example to force that the 1st deriva"ve of the spline is exact at the interval boundary
points. If z0 = zn = 0, s is called a natural spline.
Bézier curves
Bézier curves are parametrized curves in R2 , that is, r(t) = x(t)i + y(t)j,
1 0
1 0
where i := ( ), j := ( ) and x, y : [0, 1] → R.
0 1
Bernstein polynomials
Proper"es:
n
1. ∑k=0 Bkn (t) = 1 (= (t + 1 − t)n ),
2. 0 ≤ Bkn (t) ≤ 1,
3. B0n (0) = Bnn (1) = 1, otherwise, if k
= 0, Bkn (0) = 0 and if k
= n, Bkn (1) = 0.
Bézier curves
k k
conv(X) = {y ∈ R : y = ∑ λi xi , λi ∈ [0, 1], ∑ λi = 1} .
n
k=0 k=0
(n − 1)! (n − 1)!
= n[ tk−1 (1 − t)n−k − tk (1 − t)n−k−1 ]
(k − 1)!(n − k)! (k)!(n − k − 1)!
n−1
= n (Bk−1 (t) − Bkn−1 (t)) .
Therefore,
n
n
d n
β (t) = n ∑ (Bk−1
n−1
(t) − Bkn−1 (t)) xk
dt
k=0
n n−1
= n [∑ Bk−1
n−1
(t)xk − ∑ Bkn−1 (t)xk ]
k=1 k=0
n−1 n−1
= n [∑ Bkn−1 (t)xk+1 − ∑ Bkn−1 (t)xk ]
k=0 k=0
n−1
= n ∑(xk+1 − xk )Bkn−1 (t).
k=0
Bˊezier
{ dtd
d
β n (0) = n(x1 − x0 ),
dt β (1) = n(xn − xn−1 ).
n
For smoothness, we need that (x1 − x0 ) ∥ (xn − xn−1 ), i.e., x1 − x0 and xn − xn−1 are parallel.
Li$ing
Control points define the curve but the converse is not true.
Consider:
n n+1
n
β (t) = ∑ Bkn (t)xk = ∑ Bkn+1 (t)yk = αn+1 (t).
k=0 k=0
yk = (1 − ) xk +
k k
xk−1 .
n+1 n+1
De Casteljau’s algorithm
Th
n
The algorithm terminates at β0n (t) and has ( 2 ) opera"ons.
Integra"on schemes are called quadratures. Therefore, numerical integra"on methods are simply called numerical quadratures.
Note. There are no simple integra"on schemes in higher dimensions. Already 2D-cases are complicated.
Let f : [a, b] → R.
Idea. Approximate
b
∫ f (x) dx =: I
a
Lagrange:
b n b ⎛ ⎞
x − xj
∫ f (x) dx ≈ ∑ f (xi ) ∫ ∏ dx.
⎝j=0 ⎠
a i=0 a xi − xj
i=j
Let n = 1:
x−b x−a
p1 (x) = f (a) + f (b) ,
a−b b−a
so
b b
b−a
∫ f (x) dx ≈ ∫ p1 (x) dx = [f (a) + f (b)].
a a 2
⇒ Trapezoidal rule!
Error formula"on:
b b
1 b ′′
∫ f (x) dx − ∫ p1 (x) dx = ∫ f (ξ)(x − a)(x − b) dx.
a a 2 a
b
1 ′′
= f (η) ∫ (x − a)(x − b) dx.
2 a
1
=− (b − a)3 f ′′ (η).
12
b−a
Composite rule: h = n , xi = a + ih, i = 0, … , n.
b
b
h
∫ f (x) dx ≈ [f (x0 ) + 2f (x1 ) + … + 2f (xn−1 ) + f (xn )] .
a 2
Note. In this context, exactness means, that the integral and the method give the exact same result for
polynomials of certain order.
b
a+b
∫ f (x) dx = A1 f (a) + A2 f ( ) + A3 f (b),
a 2
b
∫ 1 dx = b − a ⇒ A1 + A2 + A3 = b − a.
a
b
b2 − a2 a+b b2 − a2
∫ x dx = ⇒ A1 a + A2 ( ) + A3 b = .
a 2 2 2
b 2
1 3 a+b 1
∫ x2 dx = (b − a3 ) ⇒ A1 a2 + A2 ( ) + A3 b2 = (b3 − a3 ).
a 3 2 3
Thus,
b−a
A1 = A3 =
6
and
4(b − a)
A2 = .
6
As integrals and the methods are linear, this extends to all polynomials of deg ≤ 2.
Error for n = 2:
1
(b − a)5 f (4) (η).
4!5!
Error for the composite: O(h4 ). The method is exact for cubic polynomials!
Orthogonal polynomials
Define the inner product of two real-valued polynomials on [a, b] (depends on a and b!) by:
b
⟨p, q⟩ = ∫ p(x)q(x) dx.
a
1/2
Defini!on. Two non-zero polynomials are said to be orthogonal on [a, b] if their inner product is zero. They are said to be
orthonormal if they are orthogonal and have both norm 1.
In other words, orthogonality: ⟨p, q⟩
= 0, then we write p ⊥ q .
Orthonormality: p ⊥ q and ⟨p, p⟩ = 1 = ⟨q, q⟩.
Note. The GS procedure depends on the inner product, and thus, here, on a and b.
1 1 1
1. q0 = = 1/2 = .
∥1∥ b−a
(∫a 12 dx)
b
2. For j = 1, 2, …,
j−1
q~j (x) = xqj−1 (x) − ∑⟨xqj−1 , qi ⟩qi (x),
i=0
and
q~j
qj (x) := ~ .
∥q j ∥
q~j (x) = xqj−1 (x) − ⟨xqj−1 , qj−1 ⟩qj−1 (x) − ⟨xqj−1 , qj−2 ⟩qj−2 (x)
Note. The trick ⟨xqj−1 , qi ⟩ = ⟨qj−1 , xqi ⟩ relies heavily on the fact that the inner product is defined by an integral and
that we are dealing with polynomials. The GS procedure works generally in pre-Hilbert spaces, however, then we do not
expect this kind of simplifica"on.
j−1
⟨q~j , qj−1 ⟩ = ⟨xqj−1 , qj−1 ⟩ − ∑⟨xqj−1 , qi ⟩ ⟨qi , qj−1 ⟩
i=0
=0 except when i=j−1, then it is =1
Gauss quadrature
b
b2 − a2
∫ x dx = = A0 x0 + A1 x1 .
a 2
b
1 3
∫ x2 dx = (b − a3 ) = A0 x20 + A1 x21 .
a 3
b n
∫ f (x) dx ≈ ∑ Ai f (xi ),
a i=0
where
b n
x − xj
Ai := ∫ φi (x) dx, φi (x) = ∏ ,
a xi − xj
j=0
j=i
is exact for all polynomials of degree 2n + 1 or less.
f = qn+1 pn + rn ,
Integrate,
b b b
∫ f (x) dx = ∫ qn+1 (x)pn (x) dx + ∫ rn (x) dx
a a a
=⟨qn+1 ,pn ⟩=0
b n n
= ∫ rn (x) dx = ∑ Ai rn (xi ) = ∑ Ai f (xi ).
a i=0 i=0
Because rn can be interpolated exactly with n + 1 nodes. The last equality follows from the reasoning before. □
We can extend the no"on of orthogonal polynomials to so-called weighted orthogonal polynomials with respect to the inner
product
b
⟨p, q⟩w = ∫ p(x)q(x)w(x) dx,
a
Theorem. The previous theorem holds a ⟨⋅, ⋅⟩w -orthogonal polynomial qn+1 with
b n
x − xj
Ai := ∫ φi (x)w(x) dx, φi (x) = ∏ .
a xi − xj
j=0
j=i
Example. Gauss rule on [−1, 1], n = 1. No"ce, since we only want the roots, there is no need to normalize q~i , i = 0, 1, 2.
GS: q~0 = 1.
1
1
⟨x, 1⟩ ∫ x dx
q~1 = x ⋅ 1 − ⋅ 1 = x − −1
1 ⋅ 1 = x,
⟨1, 1⟩ ∫−1 1 dx
1
−A0 A1
∫ x dx = 0 = + .
−1 3 3
From this, we obtain easily that A0 = A1 = 1. This weights could of course also been determined by integra"ng the Lagrange
polynomials over [−1, 1].
b 2 2
2 1 1
∫ x dx = = 1 ⋅ (−
2
) +1⋅( ) .
a 3 3 3
b 3 3
1 1
∫ x3 dx = 0 = 1 ⋅ (− ) +1⋅( ) .
a 3 3
Probabilis!c examples
Let Xi , i ∈ N, be i.i.d. (independent, iden"cally distributed) random variables with mean µ and variance σ 2 . Then for the
arithme"c mean (also called Césaro sum)
N
1
AN := ∑ Xi .
N
i=1
We have that
N
1 σ2
var(AN ) = 2 ∑ var(Xi ) = .
N N
i=1
In order to get the right unit, we have to consider the standard devia"on
σ
σ(AN ) = .
N
Consequence:
If our integra"on problem can be cast into an averaging problem, the convergence rate will be O( 1 ).
N
Example. Es"ma"ng the value of π . The area of a circle is A = πr2 . Set r = 1. Consider the box V = [−1, 1] × [−1, 1]
with volume ∣V ∣ = 4. The ra"o of the areas of circle enclosed by the box and the enclosing box is π4 . Let
gi = {
1, if p is inside A,
0, otherwise.
Idea: Let us sample the points pi uniformly from V . In the limit, the number of “hits” over all samples tends to the ra"o of the
areas!
Buffon’s needle
Suppose we doing a random experiment with a large number of needles of same length L that we throw on the floor, which
has parallel strips drawn on it which have all the same distance D to their neighboring strip.
Let y be the distance from the center of the needle to the closest line and let θ be the acute angle of the intersec"on point.
1
y ∼ Unif ([0, ]) ,
2
1
where y = 0 means that the needle is centered on a line and y = 2
means that y is perfectly centered between two lines.
π
θ ∼ Unif ([0, ]) ,
2
2y ≤ sin θ.
The joint probability distribu"on of two independent random variables is the product of the respec"ve distribu"ons on
[0, π2 ] × [0, 12 ]. Determining the probability requires calcula"on of the ra"o of the area of the condi"on of intersec"on in
rela"on to the total area π4 .
1 π 2
/ = .
2 4 π
By the law of large numbers, the ra"o of needles intersec"ng the lines with all needles converges to π2 ≈ 0.6366. Hence, we
have found yet another probabilis"c algorithm to determine the value of π .
Problem. (Not necessarily linear) ordinary differen"al equa"on (ODE), with ini"al value y0 at ini"al "me t0 up to a finite "me
horizon T > t0 :
{
y ′ (t) = f (t, y(t)),
y(t0 ) = y0 .
Assump!ons. Existence and uniqueness of the solu"ons are understood (by e.g. Picard itera"on).
Let us assume that f is con"nuous as a func"on from [t0 , T ] × R → R and Lipschitz con"nuous in the following sense:
There exists L > 0 such that for every y, z ∈ R, t ∈ [t0 , T ],
Euler’s method
1. y0 := y(t0 ).
2. tk := tk−1 + h and yk+1 = yk + hf (tk , yk ), k = 0, 1, 2 … ,.
h2 ′′ h2
y(tk+1 ) = y(tk ) + hy ′ (tk ) + y (ξk ) = y(tk ) + hf (tk , y(tk )) + y ′′ (ξk ),
2 2
Nota!on. y(tk ) denotes the exact solu"on to the IVP at t = tk , whereas yk denotes the result of the method at step k .
− h
yk+1 − yk h ′′
= f (tk , yk ) + y (ξk ) .
h 2
local error O(h)
yk+1 − yk
lim = y ′ (tk ) = f (tk , y(tk )).
h→0 h
What about the global error, that is, uniform convergence on [t0 , T ]?
max ∣y(tk ) − yk ∣ → 0
as h → 0?
Then Euler’s method is uniformly convergent to the exact solu"on on [t0 , T ] and the global error is O(h).
h2 ′′
dk+1 = dk + h[f (tk , y(tk )) − f (tk , yk )] + y (ξk ).
2
We get that
h2 h2
∣dk+1 ∣ ≤ ∣dk ∣ + hL∣dk ∣ + M = (1 + hL)∣dk ∣ + M .
2 2
We shall need a lemma on recursive inequali"es.
γk+1 ≤ (1 + α)γk + β,
then
enα − 1
γn ≤ enα γ0 + β.
α
Proof. Itera"ng the inequality yields
j=0
α2 ξ α2 ξ
eα = e0 + e0 α + e =1+α+ e
2 2
with ξ ∈ [0, α].
Hence
α2 ξ
1+α≤1+α+ e = eα .
2
>0
And thus,
1 − (1 + α)n enα − 1
γn ≤ enα γ0 + β ≤ enα γ0 + β.
1 − (1 − α) α
ekhL − 1 h2
∣dk ∣ ≤ ekhL ∣d0 ∣ + M.
Lh 2
Now for kh ≤ T − t0 ,
eL(T −t0 ) − 1 h
max ∣dk ∣ ≤ eL(T −t0 ) ∣d0 ∣ + M.
k L 2
∣d0 ∣ → 0 as h → 0 by the 3rd assump"on. Hence, the method converges uniformly with linear convergence rate. □
Heun’s method
h
yk+1 = yk + [f (tk , yk ) + f (tk+1 , y~k+1 )] (correction)
2
Explicit vs. Implicit
t+h
y(t + h) = y(t) + ∫ f (s, y(s)) ds,
t
h
[f (t, y(t)) + f (t + h, y(t + h))] + O(h3 ).
2
Combined, we get:
h
yk+1 = yk + [f (tk , yk ) + f (tk+1 , yk+1 )].
2
This method is implicit. Every step requires a solu"on of a nonlinear (fixed point) problem.
Heun’s method and Euler’s method are explicit.
tk+1
y(tk+1 ) = y(tk ) + ∫ f (s, y(s)) ds.
tk
Adams-Bashforth (explicit)
tk+1 m−1
yk+1 = yk + ∫ pm−1 (s) ds = yk + h ∑ bl f (tk−l , yk−l ),
tk l=0
where
1 tk+1 ⎛ s − tk−j ⎞
m−1
bl = ∫ ∏ ds.
⎝ j=0 k−l ⎠
h tk t − tk−j
j=l
yk+1 = yk + hf (tk , yk ),
Adams-Moulton (implicit)
tk+1 m
yk+1 = yk + ∫ qm (s) ds = yk + h ∑ cl f (tk+1−l , yk+1−l ),
tk l=0
where
1 tk+1 ⎛ s − tk+1−j ⎞
m
cl = ∫ ∏ ds.
⎝j=0 ⎠
h tk tk+1−l − tk+1−j
j=l
which is the so-called backward Euler method (also called implicit Euler method)!
y ′ = −15y, y(0) = 1.
General form.
where as = 1 (normaliza!on) and the coefficients a0 , … , as−1 and b0 , … , bs determine the method.
We call the mul"step method consistent if the trunca"on error is O(h) or be$er.
s−1
∑ ak = −1
k=0
and
s s−1
∑ bk = s + ∑ kak .
k=0 k=0
If, moreover,
s s−1
q∑k q−1
bk = s + ∑ k q ak ,
q
k=0 k=0
See [Ernst Hairer, Gerhard Wanner, Syvert P. Nørse$. Solving Ordinary Differen"al Equa"ons I: Nons"ff Problems. Springer,
2nd ed., 1993] for a proof.
The stability of mul"step methods depends on the convergence of the ini"al values y1 , … , ys−1 to y0 as h → 0. The second
condi"on yields a global error O(h ). p
backward Euler!
13 5 5
13 5 5
yk+2 − 3yk+1 + 2yk = h [ f (tk+2 , yk+2 ) − f (tk+1 , yk+1 ) − f (tk , yk )] .
12 3 12
13
This method sa"sfies the first condi"on. For the second condi"on, p = q = 1, we get that −1
= 12
, so the second condi"on
is not sa"sfied and the method is not stable. Indeed,
for
y ′ = 0, y(0) = 1,
which has the explicit solu"on y(t) = 1, we consider a small perturba"on of the ini"al value, δ > 0,
so that
y0 = 1, y1 = 1 + δ,
Returning to the proof of convergence for Euler, for the rounding error δ > 0,
∣dk+1 ∣ ≤ (1 + hL)∣dk ∣ + δ,
we get,
eL(T −t0 ) − 1
∣dk+1 ∣ ≤ eL(T −t0 ) ∣d0 ∣ + δ
Lh
initial error or uncertainty
dominant term, if h is sufficiently small
Gradient descent
The following algorithm is widely used in machine learning, together with its probabilis"c counterpart, the stochas"c gradient
decent (SDG).
f : D → R, D ⊂ Rd ,
ˉN
3. A!er the N th step, we may choose different outputs, as e.g. just w := wN or
N
1
ˉN :=
w ∑ wk ,
N +1
k=0
f (∑ λi xi ) ≤ ∑ λi f (xi ),
N N
i=0 i=0
N
for every x0 , x1 , … , xN ∈ Rd , whenever λi ∈ [0, 1] sa"sfy ∑i=0 λi = 1.
Con"nuously differen"able convex func"ons f : Rd → R enjoy the so-called subgradient property, i.e.
Then for
N
1
ˉN :=
w ∑ wk ,
N +1
k=0
we have that
RL
f (w
ˉN ) − m ≤ .
N +1
ˉN is doubly dependent on N ; not only through the number of steps, but also through the choice of η .
Note. The point w
Remark.
1. Assume that f has a global minimum in w∗ ∈ Rd . Then, the above result ensures the convergence of f (w
ˉN ) to the
minimum f (w∗ ), provided that R ≥ ∣w∗ ∣. Indeed, the claimed es"mate, together with
f (w
ˉN ) − f (w∗ ) ≥ 0
yields
RL
∣f (w
ˉN ) − f (w∗ )∣ ≤ .
N +1
2. It is not guaranteed that {w
ˉN }N ∈N converges to w∗ unless w∗ is the unique minimizer (e.g. if f is so-called strictly
convex (i.e., the inequality in the defini"on of convexity is strict for λ ∈ (0, 1)).
3. The convergence rate is sublinear unless f is so-called strongly convex (i.e., f − δ∣ ⋅ ∣2 is convex for some δ > 0), which
gives a linear convergence rate.
wk := wk−1 − ηvk k ∈ N,
we get that
N N
∣w∗ ∣2 η
∑⟨vk+1 , wk − w∗ ⟩ ≤ + ∑ ∣vk+1 ∣2 .
2η 2
k=0 k=0
N
1 RL
∑⟨vk+1 , wk − w∗ ⟩ ≤ ,
N +1 N +1
k=0
and
∣w∗ ∣ ≤ R, ∣vk ∣ ≤ L, k = 1, … , N + 1.
1 1 η
⟨vk+1 , wk − w∗ ⟩ = (∣wk − w∗ ∣2 + η 2 ∣vk+1 ∣2 − ∣wk − w∗ − ηvk+1 ∣2 ) = (∣wk − w∗ ∣2 − ∣wk+1 − w∗ ∣2 ) + ∣vk+1 ∣2 .
2η 2η 2
N
∣w∗ ∣2 η R2 η(N + 1)L2
+ ∑ ∣vk+1 ∣2 ≤ + = RL N + 1
2η 2 2η 2
k=0
ˉN ) = f ( ∑ wk ) ≤
N N
1 1
f (w ∑ f (wk ).
N +1 N +1
k=0 k=0
Literature
1. Anne Greenbaum and Tim P. Char"er. Numerical Methods: Design, Analysis, and Computer Implementa"on of
Algorithms, Princeton University Press, 2012.
2. L. Ridgway Sco$. Numerical Analysis, Princeton University Press, 2011.
3. Qingkai Kong, Timmy Siauw, and Alexandre Bayen. Python Programming and Numerical Methods. A Guide for Engineers
and Scien"sts. Academic Press, 2020.
4. Tobin A. Driscoll and Richard J. Braun, Fundamentals of Numerical Computa"on, SIAM, 2017.
5. Ernst Hairer, Gerhard Wanner, Syvert P. Nørse$. Solving Ordinary Differen"al Equa"ons I: Nons"ff Problems. Springer,
2nd ed., 1993.
6. Real Analysis, Wikibooks, Crea"ve Commons BY-SA 4.0.
7. Stefano Pagliarani. An introduc"on to discrete-"me stochas"c processes and their applica"ons. Lecture notes, Alma
Mater Studiorum - Università di Bologna, 2024.
8. Harri Hakula. Numerical Analysis. Lecture transcript, Aalto University, 2021.
1. jonas.tolle@aalto.fi ↩︎