
































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































































Endre S¨uli
Mathematical Institute University of Oxford
Numerical Analysis Hilary Term 2011. Lecture 1: Lagrange Interpolation.
Notation: Πn = {real polynomials of degree ≤ n}
Setup: given data fi at distinct xi, i = 0, 1 ,... , n, with x 0 < x 1 < · · · < xn, can we find a polynomial pn such that pn(xi) = fi? Such a polynomial is said to interpolate the data.
E.g.: n = 1,
linear constant
Note: degree ≤ 1 =⇒ pn ∈ Πn
Theorem. ∃pn ∈ Πn such that pn(xi) = fi for i = 0, 1 ,... , n.
Proof. Consider, for k = 0, 1 ,... , n,
Ln,k(x) = (x − x 0 ) · · · (x − xk− 1 )(x − xk+1) · · · (x − xn) (xk − x 0 ) · · · (xk − xk− 1 )(xk − xk+1) · · · (xk − xn) ∈^ Πn.^ (1)
Then
Ln,k(xi) = 0 for i = 0,... , k − 1 , k + 1,... , n and Ln,k(xk) = 1.
So now define pn(x) =
∑n k=
fkLn,k(x) ∈ Πn (2)
=⇒ pn(xi) =
∑n k=
fkLn,k(xi) = fi for i = 0, 1 ,... , n. 2
The polynomial (2) is the Lagrange interpolating polynomial.
Theorem. The interpolating polynomial of degree ≤ n is unique.
Proof. Consider two interpolating polynomials pn, qn ∈ Πn. Then their difference dn = pn − qn ∈ Πn satisfies dn(xk) = 0 for k = 0, 1 ,... , n. i.e., dn is a polynomial of degree at most n but has at least n + 1 distinct roots. Algebra =⇒ dn ≡ 0 =⇒ pn = qn. 2
Matlab:
% matlab
help lagrange LAGRANGE Plots the Lagrange polynomial interpolant for the given DATA at the given KNOTS lagrange([1,1.2,1.3,1.4],[4,3.5,3,0]);
1 1.05 1.1 1.15 1.2 1.25 1.3 1.35 1.
0
1
2
3
4
lagrange([0,2.3,3.5,3.6,4.7,5.9],[0,0,0,1,1,1]);
−40 0 1 2 3 4 5 6
−
−
−
0
10
20
30
40
50
60
This shows the important fact that the error can be large at the end points—there is a famous example due to Runge, where the error from the interpolating polynomial approximation to f (x) = (1 + x^2 )−^1 for n + 1 equally-spaced points on [− 5 , 5] diverges near ±5 as n tends to infinity: try runge from the website in Matlab.
Building Lagrange interpolating polynomials from lower degree ones.
Notation: Let Qi,j be the Lagrange interpolating polynomial at xk, k = i,... , j.
Theorem.
Qi,j(x) = (x − xi)Qi+1,j(x) − (x − xj )Qi,j− 1 (x) xj − xi^ (3)
Proof. Let s(x) denote the right-hand side of (3). Because of uniqueness, we simply wish to show that s(xk) = fk. For k = i+1,... , j−1, Qi+1,j(xk) = fk = Qi,j− 1 (xk), and hence
s(xk) = (xk − xi)Qi+1,j(xk) − (xk − xj )Qi,j− 1 (xk) xj − xi = fk.
We also have that Qi+1,j(xj) = fj and Qi,j− 1 (xi) = fi, and hence
s(xi) = Qi,j− 1 (xi) = fi and s(xj) = Qi+1,j(xj) = fj. 2
Comment: this can be used as the basis for constructing interpolating polynomials. In books: may find topics such as the Newton form and divided differences.
Generalisation: given data fi and gi at distinct xi, i = 0, 1 ,... , n, with x 0 < x 1 < · · · < xn, can we find a polynomial p such that p(xi) = fi and p′(xi) = gi?
Theorem. There is a unique polynomial p 2 n+1 ∈ Π 2 n+1 such that p 2 n+1(xi) = fi and p′ 2 n+1(xi) = gi for i = 0, 1 ,... , n.
Construction: given Ln,k(x) in (1), let
Hn,k(x) = [Ln,k(x)]^2 (1 − 2(x − xk)L′ n,k(xk)) and Kn,k(x) = [Ln,k(x)]^2 (x − xk).
Then p 2 n+1(x) =
∑n k=
[fkHn,k(x) + gkKn,k(x)] (4)
interpolates the data as required. The polynomial (4) is called the Hermite interpolating polynomial.
Theorem. Let p 2 n+1 be the Hermite interpolating polynomial in the case where fi = f (xi) and gi = f ′(xi) and f has at least 2n+2 smooth derivatives. Then, for every x ∈ [x 0 , xn],
f (x) − p 2 n+1(x) = [(x − x 0 )(x − xk− 1 ) · · · (x − xn)]^2 f (2n+2)(ξ) (2n + 2)! ,
where ξ ∈ (x 0 , xn) and f (2n+2)^ is the 2n+2-nd derivative of f.
Proof.
∫ (^) x 1 x 0 p^1 (x) dx^ =^ f^ (x^0 )
L 1 , 0 (x) ∫ (^) x 1 x 0
︷ ︸︸ ︷ x − x 1 x 0 − x 1 dx^ +f^ (x^1 )
L 1 , 1 (x) ∫ (^) x 1 x 0
︷ ︸︸ ︷ x − x 0 x 1 − x 0 dx = f (x 0 ) (x 1 − x 0 ) 2
Simpson’s Rule: n = 2:
x 0 h x 1 h x 2
f p 2
∫ (^) x 2 x 0 f^ (x) dx^ ≈^
h 3 [f (x 0 ) + 4f (x 1 ) + f (x 2 )]
Note: The Trapezium Rule is exact if f ∈ Π 1 , since if f ∈ Π 1 =⇒ p 1 = f. Similarly, Simpson’s Rule is exact if f ∈ Π 2 , since if f ∈ Π 2 =⇒ p 2 = f. The highest degree of polynomial exactly integrated by a quadrature rule is called the degree of accuracy.
Error: we can use the error in interpolation directly to obtain ∫ (^) xn x 0 [f^ (x)^ −^ pn(x)] dx^ =
∫ (^) xn x 0
π(x) (n + 1)!f^
(n+1)(ξ(x)) dx
so that ∣∣ ∣∣
∫ (^) xn x 0 [f^ (x)^ −^ pn(x)] dx
∣∣ ∣∣ ≤ 1 (n + 1)! max ξ∈[x 0 ,xn] |f (n+1)(ξ)|
∫ (^) xn x 0 |π(x)|^ dx,^ (4)
which, e.g., for the Trapezium Rule, n = 1, gives ∣∣ ∣∣ ∣∣
∫ (^) x 1 x 0 f^ (x) dx^ −^
(x 1 − x 0 ) 2 [f (x 0 ) + f (x 1 )]
∣∣ ∣∣ ∣∣ ≤^
(x 1 − x 0 )^3 12 ξ∈max[x 0 ,x 1 ]^ |f ′′(ξ)|.
In fact, we can prove a tighter result using the Integral Mean-Value Theo- rem^1 :
Theorem.
∫ (^) x 1 x 0 f^ (x) dx^ −^
(x 1 − x 0 ) 2 [f (x 0 ) + f (x 1 )] = − (x 1 − x 0 )^3 12 f ′′(ξ) for (^1) Integral Mean-Value Theorem: if f and g are continuous on [a, b] and g(x) ≥ 0 on this interval,
then there exits an η ∈ (a, b) for which
∫ (^) b a^ f^ (x)g(x) dx^ =^ f^ (η)
∫ (^) b a^ g(x) dx^ (see problem sheet).
some ξ ∈ (x 0 , x 1 ).
Proof. See problem sheet. 2
For n > 1, (4) gives pessimistic bounds. But one can prove better results such as:
Theorem. Error in Simpson’s Rule: if f ′′′′^ is continuous on (x 0 , x 2 ), then ∣∣ ∣∣ ∣∣
∫ (^) x 2 x 0 f^ (x) dx^ −^
(x 2 − x 0 ) 6 [f (x 0 ) + 4f (x 1 ) + f (x 2 )]
∣∣ ∣∣ ∣∣ ≤^
(x 2 − x 0 )^5 720 ξ∈max[x 0 ,x 2 ]^
|f ′′′′(ξ)|.
Proof. Recall
∫ (^) x 2 x 0 p^2 (x) dx^ =^
(^13) h[f (x 0 )+4f (x 1 )+f (x 2 )], where h = x 2 −x 1 =
x 1 − x 0. Consider f (x 0 ) − 2 f (x 1 ) + f (x 2 ) = f (x 1 − h) − 2 f (x 1 ) + f (x 1 + h). Then, by Taylor’s Theorem,
f (x 1 − h) f (x 1 ) − hf ′(x 1 ) + 12 h^2 f ′′(x 1 ) − 16 h^3 f ′′′(x 1 ) + 241 h^4 f ′′′′(ξ 1 ) − 2 f (x 1 ) = − 2 f (x 1 ) + +f (x 1 + h) f (x 1 ) + hf ′(x 1 ) + 12 h^2 f ′′(x 1 ) + 16 h^3 f ′′′(x 1 ) + 241 h^4 f ′′′′(ξ 2 )
for some ξ 1 ∈ (x 0 , x 1 ) and ξ 2 ∈ (x 1 , x 2 ), and hence
f (x 0 ) − 2 f (x 1 ) + f (x 2 ) = h^2 f ′′(x 1 ) + 241 h^4 [f ′′′′(ξ 1 ) + f ′′′′(ξ 2 )] = h^2 f ′′(x 1 ) + 121 h^4 f ′′′′(ξ 3 ),
the last result following from the Intermediate-Value Theorem^2 for some ξ 3 ∈ (ξ 1 , ξ 2 ) ⊂ (x 0 , x 2 ). Now for any x ∈ [x 0 , x 2 ], we may use Taylor’s Theorem again to deduce ∫ (^) x 2 x 0 f^ (x) dx^ =^ f^ (x^1 )
∫ (^) x 1 +h x 1 −h dx^ +^ f^
′(x 1 )^ ∫^ x^1 +h x 1 −h (x^ −^ x^1 ) dx
∫ (^) x 1 −h x 1 −h (x^ −^ x^1 )
(^2) dx + 16 f ′′′(x 1 )^ ∫^ x^1 +h x 1 −h (x^ −^ x^1 )
(^3) dx
∫ (^) x 1 +h x 1 −h f^
′′′′(η 1 (x))(x − x 1 ) (^4) dx = 2 hf (x 1 ) + 13 h^3 f ′′(x 1 ) + 601 h^5 f ′′′′(η 2 ) = 13 h[f (x 0 ) + 4f (x 1 ) + f (x 2 )] + 601 h^5 f ′′′′(η 2 ) − 361 h^5 f ′′′′(ξ 3 ) =
∫ (^) x 2 x 0 p^2 (x) dx^ +^
( (^) x 2 −^ x 0 2
) 5 (3f ′′′′(η 2 ) − 5 f ′′′′(ξ 3 )) (^2) Intermediate-Value Theorem: if f is continuous on a closed interval [a, b], and c is any number between f (a) and f (b) inclusive, then there is at least one number ξ in the closed interval such that f (ξ) = c. In particular, since c = (df (a) + ef (b))/(d + e) lies between f (a) and f (b) for any positive d and e, there is a value ξ in the closed interval for which d · f (a) + e · f (b) = (d + e) · f (ξ).
Numerical Analysis Hilary Term 2011. Lecture 3: Newton-Cotes Quadrature (continued).
Motivation: we’ve seen oscillations in polynomial interpolation—the Runge phenomenon–for high-degree polynomials.
Idea: split a required integration interval [a, b] = [x 0 , xn] into n equal intervals [xi− 1 , xi] for i = 1,... , n. Then use a composite rule: ∫ (^) b a f^ (x) dx^ =
∫ (^) xn x 0 f^ (x) dx^ =^
∑n i=
∫ (^) xi xi− 1 f^ (x) dx
in which each
∫ (^) xi xi− 1 f^ (x) dx^ is approximated by quadrature. Thus rather than increasing the degree of the polynomials to attain high accuracy, instead increase the number of intervals.
Trapezium Rule:
∫ (^) xi xi− 1 f^ (x) dx^ =^
h 2 [f (xi− 1 ) + f (xi)] − h^3 12 f ′′(ξi)
for some ξi ∈ (xi− 1 , xi)
Composite Trapezium Rule:
∫ (^) xn x 0 f^ (x) dx^ =^
∑n i=
h 2 [f (xi− 1 ) + f (xi)] − h^3 12 f ′′(ξi)
= h 2 [f (x 0 ) + 2f (x 1 ) + 2f (x 2 ) + · · · + 2f (xn− 1 ) + f (xn)] + eT h
where ξi ∈ (xi− 1 , xi) and h = xi − xi− 1 = (xn − x 0 )/n = (b − a)/n, and the error eT h is given by
eT h = − h^3 12
∑^ n i=
f ′′(ξi) = − nh^3 12 f ′′(ξ) = −(b − a) h^2 12 f ′′(ξ)
for some ξ ∈ (a, b), using the Intermediate-Value Theorem n times. Note that if we halve the stepsize h by introducing a new point halfway between each current pair (xi− 1 , xi), the factor h^2 in the error will decrease by four.
Another composite rule: if [a, b] = [x 0 , x 2 n], ∫ (^) b a f^ (x) dx^ =
∫ (^) x 2 n x 0 f^ (x) dx^ =^
∑n i=
∫ (^) x 2 i x 2 i− 2 f^ (x) dx
in which each
∫ (^) x 2 i x 2 i− 2 f^ (x) dx^ is approximated by quadrature. Simpson’s Rule: ∫ (^) x 2 i x 2 i− 2 f^ (x) dx^ =^
h 3 [f (x 2 i− 1 ) + 4f (x 2 i− 1 ) + f (x 2 i)] − (2h)^5 2880 f ′′′′(ξi)
for some ξi ∈ (x 2 i− 2 , x 2 i).
Composite Simpson’s Rule: ∫ (^) x 2 n x 0 f^ (x) dx^ =^
∑n i=
h 3 [f (x 2 i− 2 ) + 4f (x 2 i− 1 ) + f (x 2 i)] − (2h)
5 2880 f ′′′′(ξi)
= h 3 [f (x 0 ) + 4f (x 1 ) + 2f (x 2 ) + 4f (x 3 ) + 2f (x 4 ) + · · ·
where ξi ∈ (x 2 i− 2 , x 2 i) and h = xi − xi− 1 = (x 2 n − x 0 )/ 2 n = (b − a)/ 2 n, and the error eS h is given by
eS h = − (2h)^5 2880
∑^ n i=
f ′′′′(ξi) = − n(2h)^5 2880 f ′′′′(ξ) = −(b − a) h^4 180 f ′′′′(ξ)
for some ξ ∈ (a, b), using the Intermediate-Value Theorem n times. Note that if we halve the stepsize h by introducing a new point half way between each current pair (xi− 1 , xi), the factor h^4 in the error will decrease by sixteen.
Adaptive procedure: if Sh is the value given by Simpson’s rule with a stepsize h, then
Sh − S (^12) h ≈ −^15 16 eS h.
This suggests that if we wish to compute
∫ (^) b a f^ (x) dx^ with an absolute error ε, we should compute the sequence Sh, S (^12) h, S (^14) h,... and stop when the dif- ference, in absolute value, between two consecutive values is smaller than 16 15 ε. That will ensure that (approximately)^ |e S h| ≤ ε.
Sometimes much better accuracy may be obtained: for example, as might happen when computing Fourier coefficients, if f is periodic with period b − a so that f (a + x) = f (b + x) for all x.
adaptive_simpson(g,0,pi,8,1.0e-7); Step 1 integral is 1.7623727094, with error estimate 1.7624. Step 2 integral is 1.8011896009, with error estimate 0.038817. Step 3 integral is 1.7870879453, with error estimate 0.014102. Step 4 integral is 1.7865214631, with error estimate 0.00056648. Step 5 integral is 1.7864895607, with error estimate 3.1902e-05. Step 6 integral is 1.7864876112, with error estimate 1.9495e-06. Step 7 integral is 1.7864874900, with error estimate 1.2118e-07. Successful termination at iteration 8: The integral is 1.7864874825, with error estimate 7.5634e-09.
Numerical Analysis Hilary Term 2011. Lecture 4: Gaussian Elimination.
Setup: given a square n by n matrix A and vector with n components b, find x such that Ax = b.
Equivalently find x = (x 1 , x 2 ,... , xn)T^ for which
a 11 x 1 + a 12 x 2 + · · · + a 1 nxn = b 1 a 21 x 1 + a 22 x 2 + · · · + a 2 nxn = b 2 ... an 1 x 1 + an 2 x 2 + · · · + annxn = bn.
Lower-triangular matrices: the matrix A is lower triangular if aij = 0 for all 1 ≤ i < j ≤ n. The system (1) is easy to solve if A is lower triangular.
a 11 x 1 = b 1 =⇒ x 1 = b^1 a 11
a 21 x 1 + a 22 x 2 = b 2 =⇒ x 2 = b 2 − a 21 x 1 a 22
ai 1 x 1 + ai 2 x 2 + · · · + aiixi = bi =⇒ xi =
bi −
i∑− 1 j=
aij xj
aii
This works if, and only if, aii 6 = 0 for each i. The procedure is known as forward substitution.
Computational work estimate: one floating-point operation (flop) is one multiply (or divide) and possibly add (or subtraction) as in y = a∗x+b, where a, x, b and y are computer representations of real scalars. Hence the work in forward substitution is 1 flop to compute x 1 plus 2 flops to compute x 2 plus... plus i flops to compute xi plus... plus n flops to compute xn, or in total (^) ∑n
i=
i = 12 n(n + 1) = 12 n^2 + lower order terms
for columns j = 1, 2 ,... , n − 1 for rows i = j + 1, j + 2,... , n
row i ← row i − aij ajj ∗ row j bi ← bi − aij ajj ∗ bj
end end
Example.
x 1 x 2 x 3
=
:^ represent as
=⇒ (^) row 2 ← row 2 − 13 row 1 row 3 ← row 3 − 23 row 1
row 3 ← row 3 + 47 row 2
Back substitution:
x 3 = 2 x 2 =
7 3
x 1 =
Cost of Gaussian Elimination: note, row i ← row i − aij ajj ∗ row j is for columns k = j + 1, j + 2,... , n
aik ← aik − aij ajj ajk
end
This is approximately n − j flops as the multiplier aij /ajj is calculated with just one flop; ajj is called the pivot. Overall therefore, the cost of GE is approximately
n∑− 1 j=
(n − j)^2 =
n∑− 1 l=
l^2 = n(n − 1)(2n − 1) 6
n^3 + O(n^2 )
flops. The calculations involving b are
n∑− 1 j=
(n − j) =
n∑− 1 l=
l = n(n^ −^ 1) 2
n^2 + O(n)
flops, just as for the triangular substitution.