Docsity

Homework 1 Solutions | Numerical Analysis | MATH 128A, Assignments of Mathematical Methods for Numerical Analysis and Optimization

Toggle sidebar
bg1
MATH 128A, SUMMER 2009: HOMEWORK 1 SOLUTIONS
1.1
1(d). f(x) = x−(ln x)xis continuous when x > 1 (since ln(x)>0), hence on [4,5]. f(4) ≈0.3066 >0
and f(5) ≈ −5.799 <0, so by the intermediate value theorem there is an x∈[4,5] with f(x) = 0.
4(a). First note that f0(x)=(−ex+ 2)/3, so the only critical point of foccurs at x= ln 2, which lies in
the interval [0,1]. The maximum for |f(x)|must consequently be
max{|f(0)|,|f(ln 2)|,|f(1)|} = max{1/3,(2 ln 2)/3,(4 −e)/3}= (2 ln 2)/3.
10. The first two derivatives of f(x) = excos xare f0(x) = ex(cos x−sin x) and f00(x) = ex(−2 sin x).
Thus the second Taylor polynomial centered at π/6 is
P2(x) = √3
2eπ/6+√3−1
2eπ/6(x−π/6) −1
2eπ/6(x−π/6)2.
Since f000(x) = ex(−2 cos x−2 sin x), the error R2(x) is given by −2eξ(x)(cos ξ(x)+sin ξ(x))
3! (x−π/6)3=
−1
3eξ(x)(cos ξ(x) + sin ξ(x))(x−π
6)3, where ξ(x) is a number between π/6 and x.
(a) P2(0.5) ≈1.44688. The error is 1
3eξ(cos ξ+sin ξ)( π
6−1
2)3, for some ξ∈[0.5, π/6]. This quantity’s
maximum value is 1.01019 ·10−5, obtained when ξ=π/6; one may also overestimate it to find
an error bound: for example, |R2(0.5)|<1
3eπ/6(cos 0 + sin π
6)(π
6−1
2)3<1
3(3)1(1 + 1
2)(4
6−1
2)3≈
6.94444 ·10−3. The actual error is |R2(0.5)| ≈ 1.00265 ·10−5.
(b) There are again multiple correct ways to find a bound on |R2(x)|for x∈[0,1]. Without any
knowledge of ξ(x), the most precise approach is to notice eξ(cos ξ+sin ξ) is a positive, increasing
function of ξon [0,1]. Thus, |R2(x)| ≤ 1
3eπ/6(cos π
6+sin π
6)(π
6−x)3≤1
3eπ/6√3+1
2(π
6)3≈1.10339·
10−1when x∈[0, π/6], and |R2(x)| ≤ 1
3ex(cos x+ sin x)(x−π
6)3≤1
3e1(cos 1 + sin 1)(1 −π
6)3≈
1.35372 ·10−1when x∈[π/6,1]. Thus, the latter is a bound on |R2(x)|for x∈[0,1]. This
strategy is overkill; it’s also correct to make an estimate like |R2(x)| ≤ 1
3e1(cos 0+sin 1)|0−π
6|3≤
1
331(1 + 1)|0−4
6|3≈5.92593 ·10−1.
(c) R1
0P2(x)dx = 1.37654.
(d) Integrating the “overkill” estimates for R2(x) from (b) yields 2.93300·10−2. It’s also correct to
integrate the answer to (b) (i.e., repeat it). The actual error, 1.48276 ·10−3, is much smaller.
(This is because P2(x) both overestimates and underestimates f(x) on part of [0,1].)
23. Since 2.5 = 1+1+ 1
2, the Maclaurin polynomial in use is P2(x). This makes an error of eξ(1)
3! (1)3≤e/6.
Whoever gave an error bound of 1/6 should be fired, as it’s too low by up to (e−1)/6 [and it’s
smaller than the true error].
1.2
6(c). (121 0.327) 119 = 120.7119 = 1.7. Absolute error is .027; relative error is .016139.
6(d). (121 119) 0.327 = 2 0.327 = 1.673. This is exact.
12(a) Using L’Hospital’s Rule, we have
lim
x→0
ex−e−x
x= lim
x→0
ex+e−x
1=1+1
1= 2.
12(b) With three-digit rounding arithmetic we have e0.100 = 1.11 and e−0.100 = 0.905, so f(0.100) =
1.11−0.905
0.100 =0.205
0.100 = 2.05.
Date: Due Thursday 6/25.
1
pf2

Partial preview of the text

Download Homework 1 Solutions | Numerical Analysis | MATH 128A and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

MATH 128A, SUMMER 2009: HOMEWORK 1 SOLUTIONS

1(d). f (x) = x − (ln x)x^ is continuous when x > 1 (since ln(x) > 0), hence on [4, 5]. f (4) ≈ 0. 3066 > 0 and f (5) ≈ − 5. 799 < 0, so by the intermediate value theorem there is an x ∈ [4, 5] with f (x) = 0. 4(a). First note that f ′(x) = (−ex^ + 2)/3, so the only critical point of f occurs at x = ln 2, which lies in the interval [0, 1]. The maximum for |f (x)| must consequently be max{|f (0)|, |f (ln 2)|, |f (1)|} = max{ 1 / 3 , (2 ln 2)/ 3 , (4 − e)/ 3 } = (2 ln 2)/ 3.

  1. The first two derivatives of f (x) = ex^ cos x are f ′(x) = ex(cos x − sin x) and f ′′(x) = ex(−2 sin x). Thus the second Taylor polynomial centered at π/6 is

P 2 (x) =

eπ/^6 +

eπ/^6 (x − π/6) −

eπ/^6 (x − π/6)^2.

Since f ′′′(x) = ex(−2 cos x − 2 sin x), the error R 2 (x) is given by −^2 e

ξ(x)(cos ξ(x)+sin ξ(x)) 3! (x^ −^ π/6)

− 13 eξ(x)(cos ξ(x) + sin ξ(x))(x − π 6 )^3 , where ξ(x) is a number between π/6 and x. (a) P 2 (0.5) ≈ 1 .44688. The error is 13 eξ^ (cos ξ+sin ξ)( π 6 − 12 )^3 , for some ξ ∈ [0. 5 , π/6]. This quantity’s maximum value is 1. 01019 · 10 −^5 , obtained when ξ = π/6; one may also overestimate it to find an error bound: for example, |R 2 (0.5)| < 13 eπ/^6 (cos 0 + sin π 6 )( π 6 − 12 )^3 < 13 (3)^1 (1 + 12 )( 46 − 12 )^3 ≈

  1. 94444 · 10 −^3. The actual error is |R 2 (0.5)| ≈ 1. 00265 · 10 −^5. (b) There are again multiple correct ways to find a bound on |R 2 (x)| for x ∈ [0, 1]. Without any knowledge of ξ(x), the most precise approach is to notice eξ^ (cos ξ +sin ξ) is a positive, increasing function of ξ on [0, 1]. Thus, |R 2 (x)| ≤ 13 eπ/^6 (cos π 6 +sin π 6 )( π 6 −x)^3 ≤ 13 eπ/^6

√3+ 2 (^

π 6 )

10 −^1 when x ∈ [0, π/6], and |R 2 (x)| ≤ 13 ex(cos x + sin x)(x − π 6 )^3 ≤ 13 e^1 (cos 1 + sin 1)(1 − π 6 )^3 ≈

  1. 35372 · 10 −^1 when x ∈ [π/ 6 , 1]. Thus, the latter is a bound on |R 2 (x)| for x ∈ [0, 1]. This strategy is overkill; it’s also correct to make an estimate like |R 2 (x)| ≤ 13 e^1 (cos 0+sin 1)| 0 − π 6 |^3 ≤ 1 3 3

(c)

0 P^2 (x)dx^ = 1.37654. (d) Integrating the “overkill” estimates for R 2 (x) from (b) yields 2. 93300 · 10 −^2. It’s also correct to integrate the answer to (b) (i.e., repeat it). The actual error, 1. 48276 · 10 −^3 , is much smaller. (This is because P 2 (x) both overestimates and underestimates f (x) on part of [0, 1].)

  1. Since 2.5 = 1+1+ 12 , the Maclaurin polynomial in use is P 2 (x). This makes an error of e

ξ(1) 3! (1)

(^3) ≤ e/6. Whoever gave an error bound of 1/6 should be fired, as it’s too low by up to (e − 1)/6 [and it’s smaller than the true error].

6(c). (121 0 .327) 119 = 120. 7 119 = 1.7. Absolute error is .027; relative error is .016139. 6(d). (121 119) 0 .327 = 2 0 .327 = 1.673. This is exact. 12(a) Using L’Hospital’s Rule, we have

lim x→ 0

ex^ − e−x x

= lim x→ 0

ex^ + e−x 1

12(b) With three-digit rounding arithmetic we have e^0.^100 = 1.11 and e−^0.^100 = 0.905, so f (0.100) =

  1. 11 − 0. 905

  2. 100 =^

  3. 205

  4. 100 = 2.05.

Date: Due Thursday 6/25. 1

12(c) The third Maclaurin polynomials give

ex^ ≈ 1 + x +

x^2 +

x^3 and e−x^ ≈ 1 − x +

x^2 −

x^3 , so

f (x) =

ex^ ≈ 1 + x + 12 x^2 + 16 x^3

e−x^ ≈ 1 − x + 12 x^2 − 16 x^3

x

2 x + 13 x x

x^2.

Thus, with three-digit rounding, we have

f (0.100) ≈ 2 +

(0.100)^2 = 2 + (0.333)(0.001) = 2.00 + 0.000333 = 2. 00.

12(d) The relative error for the approximation y is |y− 2.^2003335000.^003335000 |. For (b) and (c) this gives relative error of 2. 329 × 10 −^2 and 1. 665 × 10 −^3. Note: Replacing the exponentials with Maclaurin polynomials improved accuracy by preventing the cancellation of significant digits. Simplifying the expression in part (c) is essential; omitting this step results in the same answer found in (b). 16(c). This number has a sign of + and exponent of 1023 − 1023 = 0. By inspection, the same is true for the next smallest or largest machine number. Thus, these numbers are 2−^52 smaller and 2−^52 larger than the original, respectively. In exact decimals: c−^ =1. c =1. c+^ =1.

25(a). If overflow occurs at all, it will overflow when computing m!. (k!(m − k)! is smaller.) Trial and error shows that up to m = 17 is safe, but m = 18 overflows. 25(b). m!/(m−k)! = (1)... (m−k)(m−k+1)... (m)/(1)... (m−k) = (m−k+1)... (m). So m!/k!(m−k)! = (m − k + 1)... (m)/(1)... (k) = mk · m k−− 11... m− 1 k +1. 25(c). The calculation would be m 3 · m− 2 1 · m 1 − 2. A search near

6 · 0. 9999 · 1015 finds that up to m = 181707 works. (What’s important is that this is much larger.)

6(a)–(c). O(n−^1 ), O(n−^2 ), and O(n−^2 ), respectively, since sin h = O(h) as h → 0. 6(d). ln(n + 1) − ln(n) = ln((n + 1)/n) = ln(1 + 1/n) = (1/n) − (1/n)^2 /2 + (1/n)^3 / 3 − · · · = O(n−^1 ).

8(a). There are

∑^ n

i=

∑^ i

j=

1 = n(n + 1)/2 multiplications and (n − 1) +

∑n i=1(i^ −^ 1) = (n^ −^ 1)(n^ + 1)/^2

additions. (Any answer that implies O(n^2 ) for both is acceptable.) 8(b).

∑n i=

∑i j=1 aibj^ =^

∑n i=1 ai

∑i j=1 bj^. The latter summation involves only^ n^ multiplications. 14(a). If F (h) = L + O(hp), there are constants K and δ such that |F (h) − L| ≤ K|hp| whenver |h| < δ. If q < p, we also have |F (h) − L| ≤ Kδp−q^ |h|q^ whenever |h| < δ, so F (h) = L + O(hq^ ) as well.

Extra (a) The semicolons suppressed output; without them, MATLAB would have printed the values of f and g. The .^ means to exponentiate each entry of x if x is a vector or matrix—g can be called on a list of data. (b) Multiply f (x)/1 by

x^2 + 1 + x on top and bottom. The numerator expands as (

x^2 + 1)^2 − x^2 = x^2 + 1 − x^2 = 1. (c) When a computer calculates f (x), for large x, it must subtract x from

x^2 + 1. When x is large, the first several significant (binary) digits of these numbers are the same; they are cancelled, and only the remaining bits are significant in the answer. The computation of g(10^7 ) has no such problem with catastrophic cancellation, and is therefore more accurate.

2