Sie sind auf Seite 1von 5

1

MA/CS/EGR 537
Numerical Analysis
Problem Set 2

Due: Monday February 2, 2015

Complete problems amounting to at least 80 points. The problems are from the latter half of
chapter 1 and the rst third of chapter 2.

1. (15pts) (1.11E) Let f (x) = 1 + x2 − 1
(a) Explain the diculty of computing f (x) for a small value of |x| and show how it can be
circumvented.
(b) Compute (cond f )(x) and discuss the conditioning of f (x) for small |x|.
(c) How can the answers to (a) and (b) be reconciled?
2. (20pts) (1.13E) Let f (x) = (1 − cos x)/x, x, x 6= 0.
(a) Show that direct evaluation of f is inaccurate if |x| is small; assume fl(f (x)) = fl(fl(1 −
fl(cos x))/x), where fl(cos x) = (1 + εc ) cos x, and estimate the relative error εf of fl(f (x))
as x → 0.
(b) A mathematically equivalent form of f is f (x) = sin2 x/(x(1 + cos x)). Carry out a
similar analysis as in (a), based on fl(f (x)) = fl([fl(sin x)]2 /fl(x(1 + fl(cos x)))), assuming
fl(cos x) = (1 + εc ) cos x, fl(sin x) = (1 + εs ) sin x and retaining only rst-order terms in
εs and εc . Discuss the result.
(c) Determine the condition of f (x). Indicate for what values of x (if any) f (x) is ill-
conditioned. (|x| is no longer small, necessarily.)
3. (10pts) (E1.27)Determine the condition number for the following functions:
(a) f (x) = ln x, x > 0;
(b) f (x) = cos x, |x| < 12 π ;
(c) f (x) = sin−1 x, |x| < 1;
(d) f (x) = sin−1 √ x
1+x2
.
For each indicate for what values of x the function is ill-conditioned.
4. (5pts) (E1.28) Compute the condition number of the following functions, and discuss any
possible ill-conditioning:
(a) f (x) = x1/n (x > 0, n > 0 an integer);

(b) f (x) = x − x2 − 1 (x > 1);
5. (5pts) (1.29E) Show that (condf · g)(x) ≤ (condf )(x) + (condg)(x). What can be said about
(condf /g)(x)?
2

6. (20pts) (1.36E) Dene, for x 6= 0,


dn e−x
 
n
fn = fn (x) = (−1) , n = 0, 1, 2, . . . .
dxn x

(a) Show that {fn } satises the recursion


k e−x e−x
yk = yk−1 + , k = 1, 2, 3, . . . ; y0 = .
x x x
{Hint: dierentiate k times the identity e−x = x · (e−x /x).}
(b) Why do you expect the recursion in (a), without doing any analysis to be numerically
stable if x > 0? How about x < 0?
(c) Support and discuss your answer to (b) by considering yn as a function of y0 (which for
y0 = f0 (x) yields fn = fn (x)) and by showing that the condition number of this function
at f0 is
1
(condyn )(f0 ) = ,
|en (x)|
where en (x) = 1 + x + x2 /2! + . . . + xn /n! is the nth partial sum of the exponential
series.Hint: use Leibniz's formula to evaluate fn (x).
n  
(n)
X n
(f g) = f (k) g (n−k)
k
k=0

7. (20pts) (E1.43) Consider the function f (x) = 1 − e−x on the interval 0 ≤ x ≤ 1.


(a) Show that (condf )(x) ≤ 1 on [0, 1]
(b) Let A be the algorithm that evaluates f (x) for the machine number x in oating-point
arithmetic (with machine precision eps). Assume that the exponential routine returns
ex (1 + ε), where ε ≤ eps. Estimate (condA)(x) for 0 ≤ x ≤ 1, neglecting terms of
O(eps2 ). { A Useful approximation : ln(1 + ε) = ε + O(ε2 ), ε → 0.}
(c) Plot (condf )(x) and your estimate of (condA)(x) as functions of x on [0, 1]. Comment
on the results.
8. (20pts) (M1.17) Let yn = tn e−t dt, n = 0, 1, 2, . . ..
R1
0

(a) Use integration by parts to obtain a recurrence formula relating yk to yk−1 for k =
1, 2, 3, . . ., and determine the starting value y0 .
(b) Write and run a program that generates y0 , y1 , . . . , y20 ,using the recurrence of (a), and
print the results to 15 decimal digits after the decimal point. Explain in detail (quanti-
tatively, using mathematical analysis) what is happening.
3

(c) Use the recursion of (a) in reverse order, starting (arbitrarily) with yN = 0. Place into ve
consecutive columns of a (21 × 5) matrix Y the values y0(N ) , y1(N ) , . . . , y20
(N )
thus obtained
for N = 22, 24, 26, 28, 30. Determine how much consecutive columns of Y dier from one
another by printing
ei = max |Y (:, i + 1) − Y (:, i)./Y (:, i + 1)|, i = 1, 2, 3, 4.

(The formula above uses Matlab notation for indexing arrays, Matlab's element-wise
notation for division. Also note Matlab arrays are indexed from one, not zero.) Print the
last column Y (:, 5) of Y and explain why this represents accurately the column vector of
the desired quantities y0 , y1 , . . . , y20 .
9. (15pts) (E2.1) Suppose you want to approximate the function

 −1 if −1 ≤ t < 0,
f (t) = 0 if t = 0,
1 if 0<t≤1

by a constant function φ(x) = c:


(a) on[−1, 1] in the continuous L1 norm,
(b) on {t1 , t2 , . . . , tN } in the discrete L1 norm,
(c) on [−1, 1] in the continuous L2 norm,
(d) on {t1 , t2 , . . . , tN } in the discrete L2 norm,
(e) on [−1, 1] in the ∞-norm,
(f) on {t1 , t2 , . . . , tN } in the discrete ∞-norm,
The weighting in all norms is uniform (i.e., w(t) ≡ 1, wi = 1) and ti = −1 + 2(i−1) N −1 , i =
1, 2, . . . , N . Determine the best constant c ( or constants c, if there is non-uniqueness) and
the minimum error.
10. (15pts) (E2.5) Taylor Expansion yields the simple approximation ex ≈ 1 + x, 0 ≤ x ≤ 1.
Suppose you want to improve this by seeking an approximation of the form ex ≈ 1 + cx, 0 ≤
x ≤ 1, for some suitable c.

(a) How must c be chosen if the approximation is to be optimal in the (continuous, equally
weighted) least squares sense?
(b) Sketch the error curves e1 (x) := ex − (1 + x) and e2 := ex − (1 + cx) with c as obtained
in (a) and determine max0≤x≤1 |e1 (x)| and max0≤x≤1 |e2 (x)|.
(c) Solve the analogous problem with three instead of two terms in the modied Taylor
expansion: ex ≈ 1 + c1 + c2 x2 , and provide error curves for e1 (x) = ex − 1 − x − 12 x2 and
e2 (x) = ex − 1 − c1 x − c2 xx ) = xm−1 x t−m e−t dt.
R ∞
4

11. (5pts) (E2.19) Given the recursion relation πk+1 (t) = (t−αk )πk (t)−βk πk−1 (t), k = 0, 1, 2, . . . ,
for the (monic) orthogonal polynomials {πj }, and dening β0 = kπ0 k2 k, show that kπk2 =
β0 β1 · · · βk ,k = 0, 1, 2, . . ..

12. (15pts) (E2.21)


(a) Derive the three-term recurrence relation
p p
βk+1 π̃k+1 = (t − αk )π̃k − βk π̃k−1 , k = 0, 1, 2, . . . ,
p
π̃−1 = 0, π̃0 = 1/ β0

for the orthonormal polynomials π̃k = πk /kπk k, k = 0, 1, 2, . . ..


(b) Use the result of (a) to derive the Christoel-Darboux formula
n
X p π̃n+1 (x)π̃n (t) − π̃n (x)π̃n+1 (t)
π̃k (x)π̃k (t) = βn+1 .
x−t
k=0

(c) Using the result from part (b) show that the π̃i for i = 0, 1, . . . , n form a orthogonal basis
for approximating functions on ti for i = 0, 1, n, where ti are the roots of π̃n+1 . (This
requires showing that a particular matrix A is orthogonal, i.e., AT A = AAT is diagonal.
13. (20pts) (M2.4) Write a program for discrete polynomial least squares approximation of a
function f dened on [−1, 1], using the inner product
N
2 X 2i
(u, v) = u(ti )v(ti ), ti = −1 + ,
N +1 N
i=0

Follow these steps.


(a) The recurrence coecients for the appropriate (monic) orthogonal polynomials {πk (t)}
are known explicitly:
αk = 0, k = 0, 1, . . . , N ; β0 = 2,
2 ! 
1 −1
 2  
1 k
βk = 1+ 1− 4− 2 , k = 1, 2, . . . , N.
N N +1 k

(You do not have to prove this.) Dene γk = kπk k2 = (πk , πk ), which is known to be
equal to β0 β1 · · · βk .
(b) Using the recurrence formula with coecients αk , βk given in (a), generate an array
π of dimension (N + 2, N + 1) containing πk (t` ), k = 0, 1, . . . , N + 1; ` = 0, 1, . . . , N .
(Here k is the row index and ` the column index.) Dene µk = max0≤`≤N |πk (t` )|, k =
1, 2, . . . , N + 1. Print βk , γk , and µk+1 for k = 0, 1, 2, . . . , N . where N = 10. Comment
on the results.
5

(c) With p̂n (t) = nk=0 ĉk πk (t), n = 0, 1, . . . , N , denoting the least squares approximation of
P
degree ≤ n to the function f on [−1, 1], dene
ken k2 = kp̂n − f k = (p̂n − f, p̂n − f )1/2 ,
ken k∞ = max |p̂n (ti ) − f (ti )|.
0≤i≤N

Using the array π generated in part (b), compute ĉn , ken k2 , ken k∞ , n = 0, 1, . . . , N , for
the following four functions:

f (t) = e−t , f (t) = ln(2 + t), f (t) = 1 + t, f (t) = |t|.

Be sure you compute ken k2 as accurately as possible (See discussion on page 66 of book
regarding equation (2.26)). For N = 10 and for each f , print ĉn , ken k2 , and ken k∞ for
n = 0, 1, 2, . . . , N . Comment on your results. In particular from the information provided
in the output discuss to what extent the compute coecients ĉk may be corrupted by
rounding errors.