
















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!

















Jim Lambers Math 105A Summer Session I 2003- Homework Assignment 1 Solution
f (x) > |k|^3 + 2|k| + k ≥ |k|^3 + |k| = |k|(|k|^2 + 1) ≥ 0.
Similarly, if x < −|k|, then
f (x) < −|k|^3 − 2 |k| + k ≤ −|k|^3 − |k| = −|k|(|k|^2 + 1) ≤ 0.
Therefore, by the Intermediate Value Theorem, f (x) = 0 for some x ∈ (−|k|, |k|). Because f ′(x) = 3x^2 + 2 > 0, the contrapositive of Rolle’s Theorem applies. Since f ′(x) 6 = 0 for all x, we can conclude that there is no interval [a, b] such that f (a) = f (b), for if there were, then there would exist a point c ∈ [a, b] such that f ′(c) = 0, which is a contradiction. Since f (x) never assumes the same value more than once, and it assumes the value zero at least once, it follows that f (x) = 0 for exactly one value of x.
(a) Use P 2 (0.5) to approximate f (0.5). Find an upper bound on the error |f (0.5) − P 2 (0.5)| using the error formula, and compare it to the actual error. Solution We have
f ′(x) = ex(cos x − sin x), f ′′(x) = ex(− sin x − cos x) + ex(cos x − sin x) = − 2 ex^ sin x f ′′′(x) = − 2 ex(cos x + sin x).
Therefore, f (0) = 1, f ′(0) = 1, f ′′(0) = 0,
which yields
P 2 (x) = f (0) + f ′(0)(x − 0) +
f ′′(0)(x − 0)^2
= 1 + (1)x +
(0)x^2 = 1 + x. It follows that P 2 (0.5) = 1.5, and therefore |f (0.5) − P 2 (0.5)| = | 1. 446889 − 1. 5 | = 0. 05311. The error formula is given by
R 2 (x) = − 2 eξ(x)(cos ξ(x) + sin ξ(x)) 6
x^3 ,
where ξ(x) lies between 0 and x. To estimate R 2 (0.5), we must determine the largest value, in magnitude, of f ′′′(x) on the interval [0, 0 .5]. We have f (4)(x) = − 2 ex(cos x + sin x) − 2 ex(cos x − sin x) = − 4 ex^ cos x. Since this derivative is always negative on [0, 0 .5], it follows that f ′′′(x) is decreasing on this interval, and since f ′′′(x) is also negative on this interval, we can conclude that its largest value is assumed x = 0.5, which is f ′′′(0.5) = − 4. 4747. Therefore, we have
|R 2 (x)| ≤
(b) Find a bound for the error |f (x) − P 2 (x)| in using P 2 (x) to approximate f (x) on the interval [0, 1]. Solution The error is given by |R 2 (x)|, so we must find a bound for this expression on [0, 1], just as we bounded it on [0, 0 .5] in part (a). As before, f (4)(x) < 0 on [0, 1], so f ′′′(x) is decreasing on this interval, and since it is also negative on this interval, it follows that its largest value, in magnitude, is assumed at f ′′′(1) = − 7. 512. Therefore, on [0, 1], |R 2 (x)| ≤
(c) Approximate
0 f^ (x)^ dx^ using^
0 P^2 (x)^ dx. Solution We have ∫ (^1)
0
f (x) dx ≈
0
1 + x dx
≈ x + x^2 2
1
0 ≈ 1. 5.
% cos, -sin, -cos, sin, etc. if r==0 | r==3, der=sq2; else der=-sq2; end % compute the next term of the Taylor polynomial y=y+derdx/fac; % update dx and fac. using the factorial function % or computing (x-pi/4)^i would be wasteful! dx=dx(x-pi4); fac=fac*(i+1); end
In the following MATLAB session, we use this function to approximate cos 42◦.
% convert 42 degrees to radians deg42=42*pi/
deg42 =
% compute the exact answer exact=cos(deg42)
exact =
% compute the the value of the nth polynomial for % increasing n until enough accuracy is achieved n=0; while n==0 | abs(exact-y)>1e-6, y=hw1prob1115(deg42,n) n=n+1; end
y =
y =
y =
y =
Modify your algorithm from Exercise 15 so that it computes an approximation to ex^ using Pn(x) with center x 0 = 0. Find a value of n necessary for Pn(x) to approximate ex^ to within 10 −^6 on [0, 0 .5]. Using MATLAB, show that with this value of n, your algorithm approximates ex^ to this degree of accuracy at x = 0.25. Solution The following function computes the approximation Pn(x) for given x and n.
function y=hw1prob1119(x,n) % initialize the output value y y=0; % dx will store x^i dx=1; % fac will store i! (factorial) fac=1; for i=0:n, % compute the next term of the Taylor polynomial y=y+dx/fac; % update dx and fac. using the factorial function % or computing x^i would be wasteful! dx=dxx; fac=fac(i+1); end
whenever 0 < |x − c| < δ, and x ∈ [a, b]. For each , we can choose δ = /L. Then, if 0 < |x − c| < δ, we have
|f (x) − f (c)| ≤ L|x − c| < Lδ =
This shows that f is continuous at c, and since c ∈ [a, b] is arbitrary, we conclude that f is continuous on [a, b]. (b) Show that if f has a derivative that is bounded on [a, b] by L, then f satisfies a Lipschitz condition with Lipschitz constant L on [a, b]. Solution If |f ′(x)| ≤ L on [a, b], it follows that for any two points x, y ∈ [a, b], where x 6 = y, (^) ∣ ∣ ∣∣^ f^ (x)^ −^ f^ (y) x − y
because if this was not the case, then by the Mean Value Theorem, we would have |f ′(c)| > L for some c between x and y, which is a contradiction. Multiplying through the preceding inequality by |x − y| yields the inequality
|f (x) − f (y)| ≤ L|x − y|,
and since this holds for all x, y ∈ [a, b], we conclude that f satisfies a Lipschitz condition with Lipschitz constant L on [a, b]. (c) Give an example of a function that is continuous on a closed interval but does not satisfy a Lipschitz condition on the interval. Hint: what can be said about the derivative of such a function? Solution One example is f (x) = x^1 /^3 on the interval [− 1 , 1]. It is continuous on this interval, but its derivative becomes infinite at x = 0, so it cannot satisfy a Lipschitz condition on [− 1 , 1] for any Lipschitz constant L.
(a) 150 Solution We must have |p∗^ − 150 |/| 150 | ≤ 10 −^3 , or |p∗^ − 150 | ≤ 0. 15 , which yields the interval [149. 85 , 150 .15]. (b) 900 Solution We must have |p∗^ − 900 | ≤ 0 .9, which yields [899. 1 , 900 .9].
(c) 1500 Solution We must have |p∗^ − 1500 | ≤ 1 .5, which yields [1498. 5 , 1501 .5]. (d) 90 Solution We must have |p∗^ − 90 | ≤ 0 .09, which yields [89. 91 , 90 .09].
(a) 133 + 0. 921 Solution p = 133.921 and p∗^ = 134, so the absolute error is 0.079 and the relative error is 5. 90 × 10 −^4. (b) 133 − 0. 499 Solution p = 132.501 and p∗^ = 133, so the absolute error is 0.499 and the relative error is 3. 77 × 10 −^3. (c) (121 − 0 .327) − 119 Solution p = 1.673 and p∗^ = 121 − 119 = 2, so the absolute error is 0.327 and the relative error is 0.195. (d) (121 − 119) − 0. 327 Solution p = 1.673 and p∗^ = 1.67, so the absolute error is 0.003 and the relative error is 1. 79 × 10 −^3. (e)
(^1314) − (^67) 2 e− 5. 4 Solution p = 1.95354 and p∗^ = (0. 929 − 0 .857)/(5. 44 − 5 .4) = 1.80, so the absolute error is 0.154 and the relative error is 0.0786. (f) − 10 π + 6e − 623 Solution p = − 15 .1546 and p∗^ = − 31 .4 + 16. 3 − 0 .048 = − 15 .1, so the absolute error is 0.0546 and the relative error is 3. 6 × 10 −^3. (g)
9
7
Solution p = 2/7 = 0.285714, and p∗^ = (0.222)(1.29) = 0.286, so the absolute error is
86 × 10 −^4 , and the relative error is 10−^3. (h) π− (^227) 1 17 Solution p = − 0 .0214963 and p∗^ = (3. 14 − 3 .13)/(1/17) = 0, so the absolute error is 0.0215 and the relative error is 1.
The first three nonzero terms of the Maclaurin series for the arctangent function are x − (1/3)x^3 + (1/5)x^5. Compute the absolute error and relative error in the following approxi- mations of π using the polynomial in place of the arctangent:
= lim x→ 0
− cos x − cos x + x sin x cos x = − 2.
(b) Use four-digit rounding arithmetic to evaluate f (0.1). Solution We have
f (0.1) = (0.1) cos 0. 1 − sin 0. 1
(c) Replace each trigonometric function with its third Maclaurin polynomial, and repeat part (b). Solution The third Maclaurin polynomial for cos x is 1 − 12 x^2 , and the third Maclaurin polynomial for sin x is x − 16 x^3. Substituting these polynomials for cos x and sin x in f (x), we obtain the function
f 3 (x) =
x
1 − 12 x^2
x − 16 x^3
x −
x − 16 x^3
x − 12 x^3 − x + 16 x^3 1 6 x 3
=
− 13 x^3 1 6 x^3 = − 2.
(d) The actual value is f (0.1) = − 1 .99899998. Find the relative error for the values obtained in parts (b) and (c). Solution The relative error for the value obtained in part (b) is | − 1. 941 − (− 1 .99899998)| | − 1. 99899998 |
while the relative error for the value obtained in part (c) is | − 2 − (− 1 .99899998)| | − 1. 99899998 |
(a) 0 10000001010 1001001100000000000000000000000000000000000000000000 Solution The sign bit s is 0, the exponent c is represented by 10000001010 in binary, which is 2^10 + 2^3 + 2^1 = 1024 + 8 + 2 = 1034 in decimal, and the mantissa f is
f = 2−^1 + 2−^4 + 2−^7 + 2−^8 =
Therefore, the value of the floating point number, denoted by x, is x = (−1)s 2 c−^1023 (1 + f )
= (−1)^021034 −^1023
(b) 1 10000001010 1001001100000000000000000000000000000000000000000000 Solution This number is identical to the number in part (a), except that the sign bit s is 1 instead of 0, so the value is −3224. (c) 0 01111111111 0101001100000000000000000000000000000000000000000000 Solution The sign bit s is 0, the exponent c is given by ∑^9
i=
2 i^ =
and the mantissa f is
f = 2−^2 + 2−^4 + 2−^7 + 2−^8 =
Therefore, the value of the floating point number, denoted by x, is
x = (−1)s 2 c−^1023 (1 + f )
= (−1)^021023 −^1023
Solution Using the first formula, we obtain
x =
Using the second formula, we obtain
x = 1. 31 −
The exact value, to three significant digits, is -0.0116, so clearly the second formula is better. The first formula suffers from catastrophic cancellation in the numerator.
ax + by = e, cx + dy = f,
where a, b, c, d, e, f are given, can be solved for x and y a follows:
set m = c a
, provided a 6 = 0; d 1 = d − mb; f 1 = f − me; y =
f 1 d 1
x =
e − by a
Implement this algorithm using MATLAB and solve the following linear systems.
(a)
(b)
Solution The following function solves the general two-by-two linear system, given the values of a, b, c, d, e and f.
function [x,y]=hw1prob1219(a,b,c,d,e,f) % display error message if a is zero if a==0, error(’a must be nonzero’) end m=c/a; d1=d-mb; f1=f-me; y=f1/d1; x=(e-b*y)/a;
In the following MATLAB session, this function is used to solve the systems in parts (a) and (b).
[x,y]=hw1prob1219(1.130,-6.990,8.110,12.20,14.20,-0.1370)
x =
y =
-1.
[x,y]=hw1prob1219(1.013,-6.099,-18.11,112.2,14.22,-0.1376)
x =
4.974388755065191e+
(c) What is the largest value of m for which the binomial coefficient
m 3
can be computed by the formula in part (b) without causing overflow? Solution We have ( m 3
m 3
m − 1 2
m − 2 1
m(m − 1)(m − 2) 6
To avoid overflow, this coefficient must not exceed 0. 9999 × 1015 , which implies that m must satisfy m(m − 1)(m − 2) ≤ 6(0.9999) × 1015 ≤ 5. 9994 × 1015. Since m(m − 1)(m − 2) ≤ m^3 for any nonnegative integer m, it follows that the largest value of m for which the binomial coefficient can be computed is not less than the largest value of m for which m^3 ≤ 5. 9994 × 1015. This value is (5. 9994 × 1015 )^1 /^3 ≈ (1. 81706 × 105 ) ≈ 181 , 706. If we let m = 181, 706, we obtain m(m−1)(m−2) ≈ 5. 9993 × 1015. To see if m can be any larger, we try m = 181, 707 and obtain m(m−1)(m−2) ≈ 5. 9993998 × 1015 , so this value is acceptable as well. However, if we try m = 181, 708, we obtain m(m − 1)(m − 2) ≈ 5 .9994988 which is too large, so we conclude that the largest value of m is 181,707.
(d) Use the equation in part (b) and four-digit chopping arithmetic to compute the number of possible 5-card hands in a 52-card deck. Compute the actual and relative errors. Solution The number of possible 5-card hands in a 52-card deck is ( 52 5
Using four-digit chopping arithmetic, we obtain ( 52 5
The actual value is 2,598,960, so the absolute error is 1,960 and the relative error is
i=1(1/i
(^2) ) first by 1 1 +^
1 4 + · · · + 1001 and then by 1001 + 811 + · · · + 11. Which method is more accurate, and why? Solution Let S 10 denote the sum. Using the first ordering, we have
S 10 = 1 +
Using the second ordering, we have
S 10 ≈ 0 .01 + 0.0123 + 0.0156 + 0.0204 + 0.0277 + 0.04 + 0.0625 + 0.111 + 0.25 + 1 ≈ 0 .0223 + 0.0156 + 0.0204 + 0.0277 + 0.04 + 0.0625 + 0.111 + 0.25 + 1 ≈ 0 .0379 + 0.0204 + 0.0277 + 0.04 + 0.0625 + 0.111 + 0.25 + 1 ≈ 0 .0583 + 0.0277 + 0.04 + 0.0625 + 0.111 + 0.25 + 1 ≈ 0 .0860 + 0.04 + 0.0625 + 0.111 + 0.25 + 1 ≈ 0 .126 + 0.0625 + 0.111 + 0.25 + 1 ≈ 0 .188 + 0.111 + 0.25 + 1 ≈ 0 .299 + 0.25 + 1 ≈ 0 .549 + 1 ≈ 1. 54.
Since the exact value, to 15 significant digits, is S 10 = 1.54976773116654, the second approach is clearly better. This is because when using the first ordering, small numbers are added to relatively large numbers, and as a result, significant digits of the small numbers are not included in the results of these operations. When using the second ordering, the smallest numbers are added together first, creating a larger number that is added to the larger terms, so this problem does not occur.
Therefore, in order to ensure that | 4 Pn(1) − π| < 10 −^3 , we must choose n sufficiently large so that 4/(2n + 1) < 10 −^3. This yields the inequality n > 3999 /2, so we must have n = 2000. (b) The C++ programming language requires the value of π to be within 10−^10. How many terms of the series would we need to sum to obtain this degree of accuracy? Solution Proceeding as before, we must have 4/(2n + 1) < 10 −^10. This yields the inequality n > 39 , 999 , 999 , 999 /2, so we must have n = 20, 000 , 000.
function y=hw1prob135(x,n) % y represents the sum y=0; % s is (-1)^(i+1) s=1; % xi is x^(2i-1) xi=x; % d is the denominator 2i- d=1; for i=1:n, % add the ith term y=y+sxi/d; % update variables for the next term. % how does each change as i -> i+1? % these formulas show how. s=-s; xi=xix^2; d=d+2; end
Note that each term of the series is computed by updating each factor of the term directly from the corresponding factor in the previous term. That is, (−1)(i+1)+1^ is obtained from (−1)i+1^ by negation, 2(i + 1) − 1 is obtained from 2i − 1 by adding 2, and x2(i+1)−^1 is obtained
from x^2 i−^1 by multiplying by x^2. This reduces the number of arithmetic operations, which in turn reduces roundoff error. In the following MATLAB, we use this function to approximate π using the formula
π = 16 arctan
− 4 arctan
% use one term for each arctan mypi=16hw1prob135(1/5,1)-4hw1prob135(1/239,1)
mypi =
% compute absolute error abs(mypi-pi)
ans =
% this error is too large, so we use one more term for arctan(1/5) mypi=16hw1prob135(1/5,2)-4hw1prob135(1/239,1)
mypi =
% compute absolute error abs(mypi-pi)
ans =
9.957219300997799e-
We conclude that three terms are necessary: 2 to compute arctan 15 , and 1 to compute arctan 2391.
(a) limh→ 0 sinh^ h= 1