# AM205: Assignment 1 solutions AM205: Assignment 1 solutions* Problem 1 â€“ Interpolating...

date post

21-Feb-2021Category

## Documents

view

0download

0

Embed Size (px)

### Transcript of AM205: Assignment 1 solutions AM205: Assignment 1 solutions* Problem 1 â€“ Interpolating...

AM205: Assignment 1 solutions*

Problem 1 – Interpolating polynomials for the gamma func- tion

Part (a)

We consider finding a polynomial g(x) = ∑4k=0 pkx k that fits the data points (j, Γ(j)) for

j = 1, 2, 3, 4, 5. Since there are a small number of data points, we can use the Vandermonde matrix to find the coefficients of the interpolating polynomial g(x) = ∑4k=0 gkx

k. The linear system is

1 1 1 1 1 1 2 4 8 16 1 3 9 27 81 1 4 16 64 256 1 5 25 125 625

g0 g1 g2 g3 g4

=

1 1 2 6

24

. (1)

The program gamma interp.py solves this system, and shows that the coefficients are

(g0, g1, g2, g3, g4) = (9,−16.58333, 11.625,−3.41667, 0.375). (2)

Alternatively, in exact fractions, the solution is

(g0, g1, g2, g3, g4) = (

9,−199 12

, 279 24

,−41 12

, 3 8

) . (3)

Part (b)

We now consider finding a polynomial p(x) = ∑4k=0 pkx k that fits the transformed data

points (j, log(Γ(j))) for j = 1, 2, 3, 4, 5. The coefficients are given by 1 1 1 1 1 1 2 4 8 16 1 3 9 27 81 1 4 16 64 256 1 5 25 125 625

p0 p1 p2 p3 p4

=

log 1 log 1 log 2 log 6

log 24

. (4)

The program gamma interp.py shows that the coefficients are

(p0, p1, p2, p3, p4) = (1.151,−1.921, 0.8820,−0.1187, 0.007079). (5) *Solutions were written Kevin Chen (TF, Fall 2014), Dustin Tran (TF, Fall 2014), and Chris H. Rycroft.

Edited by Chris H. Rycroft.

1

0

5

10

15

20

25

1 1.5 2 2.5 3 3.5 4 4.5 5

y

x

Γ(x) g(x) h(x)

Interpolation points

Figure 1: The gamma function Γ(x) and the two interpolating polynomials g(x) and h(x) considered in problem 1.

Parts (c) and (d)

The program gamma interp.py also outputs the gamma function and the two interpolating polynomials at 401 samples in the range 1 ≤ x ≤ 5. The three functions Γ(x), g(x), and h(x) are shown in Fig. 1. The function h(x) is near-indistinguishable from the gamma function, whereas the function g(x) is noticeably different, especially between x = 1 and x = 2. Since the gamma function grows rapidly, particularly near x = 5, its higher derivatives will grow very large, meaning that Cauchy’s interpolation bound will be large. By taking the logarithm of the function values, the interpolation in part (b) does not feature such a large increase near x = 5. Hence, it should be expected that the interpolation will be more accurate.

The program gamma interp.py also computes the maximum relative error by sampling the functions at 5001 equally spaced points over 1 ≤ x ≤ 5. It reports that the maximum relative error of g(x) is 0.286 and the maximum relative error of h(x) is 0.0115, which is consistent with the curves in Fig. 1.

Problem 2 – Error bounds with Lagrange Polynomials

Parts (a) and (b)

Figure 2 shows the Lagrange polynomial p3(x) over the true function f (x) using a slightly modified version of the in-class code example. Running the code, the infinity norm of the

2

−0.5

0

0.5

1

1.5

2

2.5

3

−1 −0.5 0 0.5 1

y

x

f (x) p3(x)

Figure 2: The function f (x) = x2ex and the interpolating polynomial p3(x) considered in problem 2.

error is approximately 0.09642.

Part (c)

The difference between f (x) and and the interpolating polynomial pn−1(x) can be ex- pressed as

f (x)− pn−1(x) = f (n)(θ)

n!

n

∏ i=1

(x− xi), (6)

where θ is a specific value within the interval from −1 to 1. To obtain a bound on ‖ f − pn−1‖∞, we consider the magnitude of the terms on the right hand side.

Since the xi are at the roots of the nth Chebyshev polynomial Tn(x), it follows that the product in Eq. 6 is a scalar multiple of this polynomial, i.e.,

n

∏ i=1

(x− xi) = λTn(x) (7)

where λ is some scaling constant. The coefficient in front of xn on the left hand side is 1. Using properties of Chebyshev polynomials, the coefficient of xn in Tn(x) is 2n−1. Hence λ = 2−(n−1). The Chebyshev polynomials satisfy |Tn(x)| ≤ 1 for x ∈ [−1, 1] and hence∣∣∣∣∣ n∏i=1(x− xi)

∣∣∣∣∣ ≤ 12n−1 (8) 3

for x ∈ [−1, 1]. Now consider the nth derivative of f . The first four derivatives are given by

f ′(x) = (2x + x2)ex, (9)

f ′′(x) = (2 + 4x + x2)ex, (10)

f ′′′(x) = (6 + 6x + x2)ex, (11)

f (4)(x) = (12 + 8x + x2)ex. (12)

These four derivatives are consistent with the general formula

f (n)(x) = (n(n− 1) + 2nx + x2)ex. (13)

To show that this is true for all n, consider using proof by induction: suppose that Eq. 13 is true for n and consider n + 1. Then

f (n+1)(x) = ex d

dx (n(n− 1) + 2nx + x2) + (n(n− 1) + 2nx + x2) d

dx ex

= ex (

2n + 2x + n(n− 1) + 2nx + x2 )

(14)

= ex ( (n + 1)((n + 1)− 1) + 2(n + 1)x + x2

) , (15)

and therefore the formula holds for n + 1 also, so it must hold for all n. The maximum value of | f (n)(θ)| can occur at two places: (i) at an internal maximum, or (ii) at one of the end points of the interval, θ = ±1. Consider case (i) first. Any internal maxima of | f (n)(θ)| would have to occur at a place where f (n+1)(θ) vanishes, corresponding to

0 = ex(n(n + 1) + 2(n + 1)θ + θ2) (16)

and therefore 0 = n(n− 1) + 2(n + 1)θ + θ2. (17)

Using the quadratic formula, the solutions are

θ = −n− 1± √ (n + 1)2 − n(n + 1) = −n− 1±

√ n + 1. (18)

When n = 1, there is one solution in the interval [−1, 1] at θ = −2 + √

2. At this point, | f ′(θ)| = 0.4612. For n > 1, there are no solutions in the interval [−1, 1].

Now consider case (ii). The values at the end points are given by

| f (n)(−1)| = (n(n− 1)− 2n + 1)e−1 = (n2 − 3n + 1)e−1 (19)

and | f (n)(1)| = |n(n− 1) + 2n + 1|e = (n2 + n + 1)e (20)

4

The value at θ = 1 is always larger than the value at θ = −1. In addition, when n = 1, the value at θ = 1 is larger than the internal maximum. Hence

‖ f (n)‖∞ = (n2 + n + 1)e (21)

for all n ≥ 1. Combining the results from Eqs. 8 & 21 establishes that

‖ f − pn−1‖∞ ≤ (n2 + n + 1)e

n! 2n−1 . (22)

Part (d)

There are many ways to find better control points, and this problem illustrates that while the Chebyshev points are a good set of points at which to interpolate a general unknown function, they are usually not optimal for a specific function.

One simple method is to examine where the maximum interpolation error is achieved. This is happens near x = 1. Hence if we move the fourth control point to the right, it will result in a better approximation of f (x) within this region. In this case, we shift the fourth control point by 0.02, which leads to an infinity norm of 0.09609.

Problem 3 – The condition number

Part (a)

Throughout this equation, ‖ · ‖ is taken to mean the Euclidean norm. The first two parts of this problem can be solved using diagonal matrices only. Consider first

B =

( 2 0 0 1

) , C =

( 1 0 0 2

) (23)

Then ‖B‖ = 2, ‖B−1‖ = 1 and hence κ(B) = 2. Similarly, κ(C) = 2. Adding the two matrices together gives

B + C =

( 3 0 0 3

) = 3I (24)

and hence κ(B + C) = ‖3I‖ ‖13 I‖ = 3× 1 3 = 1. For these choices of matrices, κ(B + C) <

κ(B) + κ(C).

Part (b)

If

B =

( 4 0 0 2

) , C =

( 1 0 0 −1

) (25)

5

then κ(B) = 2 and κ(C) = 1. Adding the two matrices together gives

B + C =

( 5 0 0 1

) (26)

and hence κ(B + C) = 5. Therefore κ(B + C) > κ(B) + κ(C).

Part (c)

Let A be an invertible 2× 2 symmetric matrix. First, note that

‖2A‖ = max v 6=0

‖2Av‖ ‖v‖ = maxv 6=0

2‖Av‖ ‖v‖ = 2 maxv 6=0

‖Av‖ ‖v‖ = 2‖A‖. (27)

Similarly, note that ‖(2A)−1‖ = ‖12 A−1‖ = 1 2‖A−1‖. Hence

κ(2A) = ‖2A‖ ‖(2A)−1‖ = 2‖A‖ × 1 2 ‖A−1‖ = ‖A‖ ‖A−1‖ = κ(A). (28)

Now suppose that A is a symmetric invertible matrix. Then there exists an orthogonal matrix Q and a diagonal matrix D such that

A = QTDQ. (29)

Since QTQ = QQT = I, it follows that

A2 = QTDQQTDQ = QTD2Q. (30)

The matrix norm of ‖A‖ is

‖A‖ = max v 6=0

‖QTDQv‖ ‖v‖ . (31)

Since Q corresponds to a rotation or reflection, it preserves distances under the Euclidean norm and hence ‖Qw‖ = ‖w‖ = ‖QTw‖ for an arbitrary vector w. Therefore

‖A‖ = max v 6=0

‖DQv‖ ‖Qv‖ = maxu 6=0

‖Du‖ ‖u‖ = ‖D‖ (32)

where u = Qv. Similarly ‖A−1‖ = ‖QTD−1Q‖, and since D−1 is also diagonal it follows that ‖A−1‖ = ‖D−1‖, so κ(A) = κ(D). With reference to the condition number notes, κ(A) = |αβ−1|where α is the d

*View more*