Docsity

Practice Final Exam Solutions - Numerical Analysis | Math 105, Exams of Mathematical Methods for Numerical Analysis and Optimization

Toggle sidebar
bg1
Jim Lambers
Math 105A
Summer Session I 2003-04
Practice Final Exam Solution
1. Use the Newton divided-difference formula to compute the cubic interpolating polynomial
p3(x) for the function
f(x) = ex,
using interpolation points x0= 0, x1= 1, x2= 2,and x3= 3.What is an upper bound for
the error |p3(0.5) −f(0.5)|?
Solution The divided-difference table for the given data is
i xif[xi]
0 0 1
1.718282
1 1 2.718282 1.476246
4.670774 0.8455357
2 2 7.389056 4.012853
12.69648
3 3 20.08554
It follows that
p3(x) = 1 + 1.718282x+ 1.476246x(x−1) + 0.8455357x(x−1)(x−2).
The error in this polynomial is
f(x)−p3(x) = eξ
4! x(x−1)(x−2)(x−3),
since f(4)(x) = ex. It follows that
|p3(0.5) −f(0.5)|=
eξ
4! (0.5)(0.5−1)(0.5−2)(0.5−3)
=
eξ
24
15
16
≤
e3
24
15
16
≤0.7845913,
since the maximum of eξon [0,3] occurs at ξ= 3.
1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Practice Final Exam Solutions - Numerical Analysis | Math 105 and more Exams Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

Jim Lambers Math 105A Summer Session I 2003- Practice Final Exam Solution

  1. Use the Newton divided-difference formula to compute the cubic interpolating polynomial p 3 (x) for the function f (x) = ex, using interpolation points x 0 = 0, x 1 = 1, x 2 = 2, and x 3 = 3. What is an upper bound for the error |p 3 (0.5) − f (0.5)|? Solution The divided-difference table for the given data is

i xi f [xi] 0 0 1

1 1 2.718282 1. 4.670774 0. 2 2 7.389056 4.

3 3 20.

It follows that

p 3 (x) = 1 + 1. 718282 x + 1. 476246 x(x − 1) + 0. 8455357 x(x − 1)(x − 2).

The error in this polynomial is

f (x) − p 3 (x) = e

ξ 4!

x(x − 1)(x − 2)(x − 3),

since f (4)(x) = ex. It follows that

|p 3 (0.5) − f (0.5)| =

∣∣^ e

ξ 4! (0.5)(0.^5 −^ 1)(0.^5 −^ 2)(0.^5 −^ 3)

∣∣^ e

ξ 24

∣∣^ e

3 24

since the maximum of eξ^ on [0, 3] occurs at ξ = 3.

  1. Find the Hermite interpolating polynomial for the following data.

i xi f (xi) f ′(xi) 0 − 1 0 1 1 0 1 0 2 1 4 − 1

Solution We define

z 0 = x 0 , z 1 = x 0 , z 2 = x 1 , z 3 = x 1 , z 4 = x 2 , z 5 = x 2. The divided-difference table for the given data is

i zi f [zi] 0 − 1 0 1 1 − 1 0 0 1 − 1 2 0 1 − 1 1. 0 2 − 3 3 0 1 3 − 4. 5 3 − 7 4 1 4 − 4 − 1 5 1 4

It follows that the Hermite interpolating polynomial is

H 5 (x) = (x + 1) − (x + 1)^2 x + 1.5(x + 1)^2 x^2 − 3(x + 1)^2 x^2 (x − 1).

  1. Find the cubic spline interpolant s(x) for the data

i xi f (xi) 0 1 − 1 1 3 3 2 5 0

that satisfies free, or natural, boundary conditions. Solution The spline s(x) is a piecewise polynomial consisting of the two pieces

s 0 (x) = a 0 + b 0 (x − 1) + c 0 (x − 1)^2 + d 0 (x − 1)^3 , s 1 (x) = a 1 + b 1 (x − 3) + c 1 (x − 3)^2 + d 1 (x − 3)^3.

Solution Given a function f (x), we can approximate f ′(x 0 ) by computing p′ 2 (x 0 ), where p 2 (x) is the polynomial that interpolates f (x) at the points x 0 − h, x 0 , and x 0 + 2h. The Lagrange polynomials for these points are given by

L 2 , 0 (x) =

(x − x 0 )(x − (x 0 + 2h)) (x 0 − h − x 0 )(x 0 − h − (x 0 + 2h))

= x

(^2) − (2x 0 + 2h)x + x 0 (x 0 + 2h) 3 h^2

L 2 , 1 (x) = (x^ −^ (x^0 −^ h))(x^ −^ (x^0 + 2h)) (x 0 − (x 0 − h))(x 0 − (x 0 + 2h))

= x

(^2) − (2x 0 + h)x + (x 0 − h)(x 0 + 2h) − 2 h^2

L 2 , 2 (x) = (^) (x (x^ −^ (x^0 −^ h))(x^ −^ x^0 ) 0 + 2h^ −^ (x 0 −^ h))(x 0 + 2h^ −^ x 0 ) =

x^2 − (2x 0 − h)x + (x 0 − h)x 0 6 h^2.

Differentiating, we obtain

L′ 2 , 0 (x) = 2 x^ −^ (2x^0 + 2h) 3 h^2

L′ 2 , 1 (x) = 2 x^ −^ (2x^0 +^ h) − 2 h^2

L′ 2 , 2 (x) = 2 x^ −^ (2x^0 −^ h) 6 h^2

which yields

L′ 2 , 0 (x 0 ) =

3 h ,^ L

′ 2 , 1 (x^0 ) =^

2 h ,^ L

′ 2 , 2 (x^0 ) =^

6 h. We conclude that if p 2 (x) is the polynomial that interpolates f (x) at the points x 0 − h, x 0 , and x 0 + 2h, then because

p 2 (x) = f (x 0 − h)L 2 , 0 (x) + f (x 0 )L 2 , 1 (x) + f (x 0 + 2h)L 2 , 2 (x),

we have

f ′(x 0 ) ≈ p′ 2 (x 0 ) = f (x 0 − h) −^2 3 h

  • f (x 0 )^1 2 h

  • f (x 0 + 2h)^1 6 h = −^4 f^ (x^0 −^ h) + 3f^ (x^0 ) +^ f^ (x^0 + 2h) 6 h

From Taylor’s Theorem,

f (x 0 − h) = f (x 0 ) − f ′(x 0 )h +

f ′′(x 0 ) 2 h

(^2) − f^ ′′′(ξ^1 ) 6 h

f (x 0 + 2h) = f (x 0 ) + f ′(x 0 )2h + f^

′′(x 0 ) 2 4 h

(^2) + f^ ′′′(ξ^2 ) 6 8 h

where ξ 1 ∈ [x 0 − h, x 0 ] and ξ 2 ∈ [x 0 , x 0 + 2h]. Substituting these Taylor expansions into the differentiation rule yields

− 4 f (x 0 − h) + 3f (x 0 ) + f (x 0 + 2h) 6 h

3 h

[

f (x 0 ) − f ′(x 0 )h + f^

′′(x 0 ) 2

h^2 − f^

′′′(ξ 1 ) 6

h^3

]

2 h f^ (x^0 ) + 1 6 h

[

f (x 0 ) + f ′(x 0 )2h + f^

′′(x 0 ) 2

4 h^2 + f^

′′′(ξ 2 ) 6

8 h^3

]

= f ′(x 0 ) − 2 3 h

[

f ′′(x 0 ) 2

h^2 − f^

′′′(ξ 1 ) 6

h^3

]

6 h

[

f ′′(x 0 ) 2

4 h^2 + f^

′′′(ξ 2 ) 6

8 h^3

]

= f ′(x 0 ) + O(h^2 ),

since the terms of O(h) cancel.

  1. Use Romberg integration to compute an approximation to

∫ (^1)

− 1

ex^ cos 2x dx

that is sixth-order accurate. Solution We begin by using the Trapezoidal Rule, or, equivalently, the Composite Trape- zoidal Rule ∫ (^) b

a

f (x) dx ≈

h 2

f (a) +

n∑− 1

j=

f (xj ) + f (b)

 (^) , h = b^ −^ a n ,^ xj^ =^ a^ +^ jh,

with n = 1 subintervals. Since h = (b − a)/n = (1 − (−1))/1 = 2, we have

R 1 , 1 =

2 [f^ (−1) +^ f^ (1)] =^ −^1.^28429624943104.

  1. Use Gaussian Quadrature with n = 3 to evaluate the integral ∫ (^1)

0

sin^3 x dx.

What is the degree of this quadrature rule? Solution The particular Gaussian quadrature rule that we will use consists of 3 nodes x 1 , x 2 and x 3 , and 3 weights w 1 , w 2 and w 3. To determine the proper nodes and weights, we use the fact that the nodes and weights of a 3-point Gaussian rule for integrating over the interval [− 1 , 1] are given by

i Nodes r 3 ,i Weights c 3 ,i 1 0. 7745966692 0. 5555555556 2 0. 0000000000 0. 8888888889 3 − 0. 7745966692 0. 5555555556

To obtain the corresponding nodes and weights for integrating over [− 1 , 1], we can use the fact that in general, ∫ (^) b

a

f (x) dx =

− 1

f

b − a 2 t^ +^

a + b 2

b − a 2 dt, as can be shown using the change of variable x = [(b − a)/2]t + (a + b)/2 that maps [a, b] into [− 1 , 1]. We then have ∫ (^) b

a

f (x) dx =

− 1

f

b − a 2 t^ +^

a + b 2

b − a 2 dt

≈

∑^5

i=

f

b − a 2

r 3 ,i + a^ +^ b 2

b − a 2

c 3 ,i

∑^5

i=

f (xi)wi,

where xi = b^ −^ a 2

r 3 ,i + a^ +^ b 2

, wi = b^ −^ a 2

c 3 ,i, i = 1,... , 5. In this example, a = 0 and b = 1, so the nodes and weights for a 3-point Gaussian quadrature rule for integrating over [0, 1] are given by

xi =^1 2

r 3 ,i +^1 2

, wi =^1 2

c 3 ,i, i = 1,... , 3 ,

which yields

i Nodes xi Weights wi 1 0.8872983346 0. 2 0.5000000000 0. 3 0.1127016654 0.

It follows that ∫ (^1)

0

sin^3 x dx ≈

∑^3

i=

wi sin^3 xi

≈ 0 .2777777778 sin^3 0 .8872983346 + 0.4444444444 sin^3 0 .5 + 0 .2777777778 sin^3 0. 1127016654 ≈ 0. 17885657811021.

Since the Gaussian quadrature rule has 3 nodes, its degree is 2(3) − 1 = 5.

  1. Use the Composite Trapezoidal Rule with m = n = 2 to evaluate the double integral ∫ (^1)

0

0

e−(x+y)^ dy dx.

Solution The Composite Trapezoidal Rule with n = 2 subintervals is ∫ (^) b

a

f (x) dx ≈ h 2

[

f (a) + 2f

a + b 2

  • f (b)

]

, h = b^ −^ a n

If a = 0 and b = 1, then h = (1 − 0)/2 = 0.5 and this simplifies to ∫ (^1)

0

f (x) dx ≈ 1 4

[f (0) + 2f (0.5) + f (1)].

If we use this rule to evaluate the integrand

f (x) =

0

e−(x+y)^ dy,

at any given x, and also to integrate f (x) over [0, 1], we obtain ∫ (^1)

0

0

e−(x+y)^ dy dx =

0

f (x) dx

≈ 1 4

[f (0) + 2f (0.5) + f (1)]

≈ 1 4

[∫ 1

0

e−(0+y)^ dy + 2

0

e−(0.5+y)^ dy +

0

e−(1+y)^ dy

]

We can approximate this integral using the Composite Simpson’s Rule ∫ (^) b

a

f (x) dx ≈ h 3

[f (a) + 4f (x 1 ) + 2f (x 2 ) + 4f (x 3 ) + · · · + 2f (xn− 2 ) + 4f (xn− 1 ) + f (b)] ,

with n = 4 and h = 1 − 4 0 = 1/ 4 , which yields

∫ (^1)

0

G(x) dx ≈ 1 /^4 3

[G(0) + 4G(0.25) + 2G(0.5) + 4G(0.75) + G(1)]

[0 + 4(− 0 .00000067741204) + 2(− 0 .00003055376764) +

4(− 0 .00028258394627) − 0 .00136436079853]

The second integral can be evaluated analytically. We have

∫ (^1)

0

1 − x^2 / √2 + x^4 / 24 x dx^ = 2x

5 x

5 / 2 +^1

9 x

9 / 2

1

0

and therefore ∫ (^1)

0

cos √ x x

dx =

0

cos x (^) √− p 4 (x) x

dx +

0

p (^4) √(x) x

dx ≈ − 0 .00021320948059 + 1. 80925925925926 ≈ 1. 80904604977867.