0% found this document useful (0 votes)
112 views16 pages

Math 104A HW 01 Solution Key: 1.1 Review of Calculus

This document contains solutions to homework problems from a calculus course. It begins by providing guidelines for collaboration on homework assignments. It then works through multiple calculus problems, showing the steps to find derivatives and integrals, apply theorems like the intermediate value theorem and Rolle's theorem, and use Taylor polynomial approximations. For each problem, it provides the full working to arrive at the solution.

Uploaded by

Pallabi Saha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views16 pages

Math 104A HW 01 Solution Key: 1.1 Review of Calculus

This document contains solutions to homework problems from a calculus course. It begins by providing guidelines for collaboration on homework assignments. It then works through multiple calculus problems, showing the steps to find derivatives and integrals, apply theorems like the intermediate value theorem and Rolle's theorem, and use Taylor polynomial approximations. For each problem, it provides the full working to arrive at the solution.

Uploaded by

Pallabi Saha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

1.

1 Review of Calculus Solutions by Jon Lo Kim Lin - Fall 2014

MATH 104A HW 01 SOLUTION KEY


You are encouraged to collaborate with your classmates and utilize internet resources provided you
adhere to the following rules:

(i) You read the problem carefully and make a serious effort to solve it before you ask for help.

(ii) You write the solution in your own words/ handwriting/ LATEX document.

(iii) You credit the people/books/websites who helped you, especially if they showed you how to
do most of the problem.

(iv) The TA is not omniscient. This course is aimed at developing your deductive reasoning and
incredulity.

For those who need a quick primer on programming, I highly recommend the python course by
http://www.codecademy.com. It’s free and they claim you can learn python in a mere 13 hours.

1.1 Review of Calculus


1. Show that the following equations have at least one solution in the given intervals.

(a) x cos x − 2x 2 + 3x − 1 = 0, [0.2, 0.3] and [1.2, 1.3]


(b) (x − 2)2 − ln x = 0, [1, 2] and [e, 4]
(c) 2x cos(2x) − (x − 2)2 = 0, [2, 3] and [3, 4]
(d) x − (ln x)x = 0, [4, 5]

SOLUTION. First, notice that we are not asked to find the zeros of any of these functions;
we simply need to argue that such solutions exist. Now, an application of the intermediate
value theorem makes it plain that it suffices to show that each of the given functions changes
sign within the given interval.

(a) Since f (0.2) = −0.283987 and f (0.3) = 0.00660095, by the intermediate value theo-
rem, our function f must admit a zero in the interval [0.2, 0.3]. In the second case, again,
the root is furnished since f (1.2) = 0.154829 and f (1.3) = −0.132252
(b) Since f (1) = 1 and f (2) = − ln(2) ≈ −0.693147, by the intermediate value theorem,
our function f must admit a zero in the interval [1, 2]. In the second case, again, the root
is furnished since f (e) = 3 − 4e + e 2 ≈ −0.484071 and f (4) = 4 − ln(4) ≈ 2.61371
(c) Since f (2) = 4 cos 4 ≈ −2.61457 and f (3) = 6 cos 6−1 ≈ 4.76102, by the intermediate
value theorem, our function f must admit a zero in the interval [2, 3]. In the second case,
again, the root is furnished since f (4) = 8 cos 8 − 4 ≈ −5.164.
(d) Since f (4) ≈ 0.306638 and f (5) ≈ −5.79869,, by the intermediate value theorem, our
function f must admit a zero in the interval [4, 5].

1
1.1 Review of Calculus Solutions by Jon Lo Kim Lin - Fall 2014

3. Show that f 0 (x) is 0 at least once in the given intervals.

(a) f (x) = 1 − e x + (e − 1) sin((π/2)x), [0, 1]


(d) f (x) = (x − 2) sin x ln(x + 1), [−1, 3]

SOLUTION. As in the previous problem, we simply need to argue that such solutions exist.
More specifically, we need to show that the given functions satisfy the conditions of Rolle’s
theorem. The calculations are routine so we’ll spare you the details. 

8. Find the
√ third
√ Taylor
√ polynomial P
√ 3 (x) for the function f (x) = x + 1 about x0 = 0. Approx-
imate 0.5, 0.75, 1.25, and 1.5 using P3 (x), and find the actual errors.

SOLUTION. A direct calculation makes it plain that

f (0) = 1
1 1
f 0 (x) = √ ⇒ f 0 (0) =
2 x +1 2
1 1
f 00 (x) = − ⇒ f 00
(0) = −
4(x + 1)3/2 4
3 3
f 000 (x) = 5/2
⇒ f 000 (0) =
8(x + 1) 8
By invoking Taylor’s theorem we see that the third Taylor polynomial for f about the point
x0 = 0 is given by
f 00 (x0 ) f 000 (x0 )
P3 (x) = f (x0 ) + f 0 (x0 )(x − x0 ) + (x − x0 )2 + (x − x0 )3
2! 3!
0 f 00 (0) 2 f 000 (0) 3
= f (0) + f (0)x + x + x
2! 3!
= 1 + 12 x − 18 x 2 + 16
1 3
x .

The actual errors are generated from the python code we list below:
from math i m p o r t f a b s , s q r t # O n l y i m p o r t what i s necessary

d e f f ( x ) : # The a c t u a l f u n c t i o n
return s q r t ( x +1.0)

d e f p3 ( x ) : # The t h i r d T a y l o r p o l y n o m i a l
return 1.0+(1/2.0)∗ x −(1/8.0)∗( x ∗∗2)+(1/16.0)∗( x ∗∗3)

def p3_error ( x ) : # C a l c u l a t e s the e r r o r


r e t u r n f a b s ( f ( x )−p3 ( x ) )

sqrt_input =[0.5 , 0.75 , 1.25 , 1.5]

2
1.1 Review of Calculus Solutions by Jon Lo Kim Lin - Fall 2014

for i in range ( len ( sqrt_input ) ) :


x r a n g e [ i ]= s q r t _ i n p u t [ i ] −1.0

for x in xrange :
p r i n t ’ ␣ x =%8.7 f ␣ p3 ( x )=%11.7 e ␣ f ( x )=%11.7 e ␣ e r r o r =%11.7 e ’ % \
( x , p3 ( x ) , f ( x ) , p 3 _ e r r o r ( x ) )

x P3 (x) f (x) = x + 1 kf (x) − P3 (x)k
-0.5000000 7.1093750e-01 7.0710678e-01 3.8307188e-03
-0.2500000 8.6621094e-01 8.6602540e-01 1.8553372e-04
0.2500000 1.1181641e+00 1.1180340e+00 1.3007375e-04
0.5000000 1.2265625e+00 1.2247449e+00 1.8176286e-03

9. Find the second Taylor polynomial P2 (x) for the function f (x) = e x cos x about x0 = 0.
(a) Use P2 (0.5) to approximate f (0.5). Find an upper bound for error kf (0.5) − P2 (0.5)k
using the error formula, and compare it to the actual error.
(b) Find a bound for the error kf (x) − P2 (x)k in using P2 (x) to approximate f (x) on the
interval [0, 1].
R1 R1
(c) Approximate 0 f (x) dx using 0 P2 (x) dx.
R1
(d) Find an upper bound for the error in (c) using 0 kR2 (x)k dx and compare the bound to
the actual error.

SOLUTION. A direct calculation makes it plain that


f (0) = 1
f 0 (x) = e x (cos x − sin x) ⇒ f 0 (0) = 1
f 00 (x) = −2e x sin x ⇒ f 00 (0) = 0,
f 000 (x) = −2e x (cos x + sin x).
By invoking Taylor’s theorem we see that the 2nd Taylor polynomial for f about the point
x0 = 0 is given by
f 00 (x0 )
P2 (x) = f (x0 ) + f 0 (x0 )(x − x0 ) + (x − x0 )2
2!
f 00 (0) 2
= f (0) + f 0 (0)x + x
2!
= 1 + x,
with the corresponding remainder
f 000 (ξ) −2e ξ (cos ξ + sin ξ) 3
R2 (x) = (x − x0 )3 = x ,
3! 3!
with ξ betwixt x and 0.

3
1.1 Review of Calculus Solutions by Jon Lo Kim Lin - Fall 2014

(a) From a routine computation we find that

kf (0.5) − P2 (0.5)k = kR2 (0.5)k


−2e ξ (cos ξ + sin ξ)

3

= (0.5)
3!
2(0.5)3
≤ max ke ξ (cos ξ + sin ξ)k,
3! 0≤ξ≤0.5

where the maximum on the right-hand-side of the inequality is furnished by the extreme
value theorem. To establish a upper bound it remains to maximize the function

g(ξ) = e ξ (cos ξ + sin ξ)

over the interval [0, 0.5]. Since g 0 (ξ) = 2e ξ cos ξ is positive over the interval (0, 0.5), it
follows by the mean value theorem that the function g is strictly increasing over the
interval [0, 0.5]. Since the maximum value of g must be attained, we see that g attains
its maximum value at the point x0 = 0.5 Therefore; the error bound is:

2(0.5)3 0.5
kf (0.5) − P2 (0.5)k ≤ ke (cos(0.5) + sin(0.5))k
3!
2(0.5)3 0.5
≤ ke kk cos(0.5) + sin(0.5))k
3!
≈ 9.3222005e-02,

whereas the exact error is:

kf (0.5) − P2 (0.5)k = ke 0.5 cos(0.5) − 1.5k ≈ 5.3110963e-02

(b) Using the argument presented in part (a), we find that

kf (x) − P2 (x)k = kR2 (x)k


−2e ξ (cos ξ + sin ξ) 3

= x
3!
2
≤ max kxk3 max ke ξ (cos ξ + sin ξ)k
3! 0≤x≤1 0≤ξ≤x
| {z }
1
2
≤ max ke ξ (cos ξ + sin ξ)k
3! 0≤ξ≤1

where the maximum on the right-hand-side of the inequality is furnished by the extreme
value theorem. To establish a upper bound it remains to maximize the function

g(ξ) = e x (cos x + sin x)

g(ξ) = e ξ (cos ξ + sin ξ)


over the interval [0, 1]. Since g 0 (ξ) = 2e ξ cos ξ is positive over the interval (0, 1), it follows
by the mean value theorem that the function g is strictly increasing over the interval

4
1.1 Review of Calculus Solutions by Jon Lo Kim Lin - Fall 2014

[0, 1]. Therefore, the maximum is attained at ξ0 = 1, thus;


2
kf (x) − P2 (x)k = kR2 (x)k ≤ max ke ξ (cos ξ + sin ξ)k
3! 0≤ξ≤1
1
≤ ke 1 (cos 1 + sin 1) k
3
e (cos 1 + sin 1)
≤ ≈ 1.2520164e+00
3

(c)
Z 1 Z 1
f (x) dx ≈ P2 (x) dx
0 0
Z 1
= (1 + x) dx
0
x 2 i1
 
= x+
2 x=0
3
= .
2

(d) By the triangle inequality for integrals we see that


Z b Z b


φ(x) dx kφ(x)k dx,


a a

5
1.1 Review of Calculus Solutions by Jon Lo Kim Lin - Fall 2014

for any piecewise-continuous φ on the interval [a, b]. More specifically,


Z 1 Z 1 Z 1


f (x) dx − P2 (x) dx
=
[f (x) − P2 (x)] dx
0 0 0
Z 1
≤ kf (x) − P2 (x)k dx
0
Z 1
= kR2 (x)k dx
0
Z 1
−2e ξ (cos ξ + sin ξ) 3

=
dx
x
0
3!
Z 1
2
e ξ (cos ξ + sin ξ) x 3 dx
=
0 3!
Z 1
2
≤ max e ξ (cos ξ + sin ξ) x 3 dx
0 3! 0≤ξ≤x
Z 1
e(cos 1 + sin 1)
x 3 dx

0 3
e(cos 1 + sin 1) 1
Z

= x 3 dx
3 0
Z 1
e(cos 1 + sin 1)
= x 3 dx, since kx 3 k = x 3 for x ≥ 0,
3 0
e(cos 1 + sin 1) x 4 i1
= , since x 3 > 0 for 0 ≤ x ≤ 1,
3 4 x=0
e(cos 1 + sin 1)
=
12
≈ 3.1300410e-01.

Next, by the result established in part (c)


Z 1 Z 1 Z 1

3
f (x) dx − P 2 (x) dx = f (x) dx − . (1)

0 0

0 2

Now, integration by parts makes it plain that


Z 1 Z 1
f (x) dx = e x cos x dx
0 0
1 i1
= e x (sin x + cos x)
2 x=0
1
= (e(sin 1 + cos 1) − 1),
2
hence; the actual error becomes

1 3
(e(sin 1 + cos 1) − 1) − ≈ 1.2197539e-01
2 2

6
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014

10. Repeat Exercise 9 using x0 = π/6.

SOLUTION. The calculations are routine and follow the pattern established in the previous
problem. We’ll spare you the details. 

15. Use a Taylor polynomial about π/4 to approximate cos(42◦ ) to an accuracy of 10−6 .


SOLUTION. First note that 42◦ degrees equates to radians. Since we are expanding
30
f (x) = cos x about the point x0 = π/4, it suffices to determine the truncation number n for
which the remainder satisfies the prescribed accuracy. In other words, find n for which
−6
kRn ( 7π
30 )k < 10 .

A direct calculation makes it plain that f n+1 (x) ∈ {± cos x, ± sin x}, hence; kf n+1 (x)k ≤ 1 for
all x ∈ R. Therefore,

f n+1 (ξ)  7π π n+1
kRn ( 7π
30 )k = −

(n + 1)! 30 4


n+1  
f (ξ)
π
n+1
= (n + 1)! 60
1  π n+1

(n + 1)! 60

The last inequality is below 10−6 for all n ≥ 3, hence P3 (x) ought to suffice. The remaining
calculations are routine and we’ll spare you the details. 

25. A Maclaurin polynomial for e x is used to give the approximation 2.5 to e. The error bound in
this approximation is established to be E = 16 . Find a bound for the error in E.

1.2 Round-off Errors and Computer Arithmetic


1. Compute the absolute error and relative error in approximations of p by p ∗ .

(a) p = π, p ∗ = 22/7

(d) p = 2, p ∗ = 1.414
(f) p = 10π, p ∗ = 1400

SOLUTION.
Absolute error relative error
(a) 1.2644893e-03 4.0249943e-04
(d) 2.1356237e-04 1.5101140e-04
(f) 1.3685841e+03 4.3563384e+01
The tableaux was generated using the python code listed below:

7
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014

from math i m p o r t f a b s , s q r t , p i # O n l y i m p o r t what i s necessary

def abs_error ( x , x s t a r ) : # C a l c u l a t e s the a b s o l u t e e r r o r


r e t u r n f a b s ( x− x s t a r )

def r e l _ e r r o r ( x , x s t a r ) : # C a l c u l a t e s the r e l a t i v e error


r e t u r n f a b s ( x− x s t a r ) / f a b s ( x )

p =[ pi , s q r t ( 2 ) , 10.0∗ p i ]
pstar =[22.0/7.0 , 1.414 ,1400]

for i in 0 ,1 ,2:
p r i n t ’ ␣ a b s o l u t e ␣ e r r o r ␣ =%11.7 e ␣ ␣ r e l a t i v e ␣ e r r o r =%11.7 e ’ \
% ( abs_error (p [ i ] , pstar [ i ]) , rel_error (p [ i ] , pstar [ i ] ) )

2. Find the largest interval in which p ∗ must lie to approximate p with relative error at most 10−4
for each value of p.

(a) π

(c) 2


SOLUTION. Since both π, 2 > 0, without loss of generality, we see that in both cases
kp − p ∗ k kp − p ∗ k
≤ 10−4 ⇐⇒ ≤ 10−4 ⇐⇒ kp − p ∗ k ≤ p · 10−4 ,
kpk p
hence;
−p · 10−4 ≤ p − p ∗ ≤ p · 10−4 ,
first, subtracting p from each inequality we obtain:

−p − p · 10−4 ≤ −p ∗ ≤ −p + p · 10−4 ,

second, multiplying by a factor of −1, reverses the inequalities:

p + p · 10−4 ≥ p ∗ ≥ p − p · 10−4 ,

or equivalently,
p − p · 10−4 ≤ p ∗ ≤ p + p · 10−4 ,
thus;
p(1 − 10−4 ) ≤ p ∗ ≤ p(1 + 10−4 ).
The intervals are precisely,
√ √
[π(1 − 10−4 ), π(1 + 10−4 )] and [ 2(1 − 10−4 ), 2(1 + 10−4 )].

8
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014

5. Use three-digit rounding arithmetic to perform the following calculations. Compute the abso-
lute error and relative error with the exact value determined to at least five digits.

(a) 133 + 0.921


(c) (121 − 0.327) − 119
3
(f) −10π + 6e −
62
22
π− 7
(h) 1
17
P∞
10. The number e can be defined by e = n=0 (1/n!), where n! = n(n − 1) · · · 2 · 1 for n 6= 0 and
0! = 1. Compute the absolute error and relative error in the following approximations of e :
5 10
X 1 X 1
(a) (b)
n=0
n! n=0
n!

SOLUTION. The errors are generated from the python code we list below:
from math i m p o r t f a b s , e , factorial # O n l y i m p o r t what i s necessary

def abs_error (p , p s t a r ) : # C a l c u l a t e s the a b s o l u t e e r r o r


r e t u r n f a b s ( p−p s t a r )

def r e l _ e r r o r (p , p s t a r ) : # C a l c u l a t e s the r e l a t i v e error


r e t u r n f a b s ( p−p s t a r ) / f a b s ( p )

d e f cumFact ( k ) :
r e t u r n sum ( 1 . 0 / f l o a t ( f a c t o r i a l ( n ) ) f o r n i n r a n g e ( k ) )

k_range = [ 5 , 1 0 ]

for i in 0 ,1:
k=k_range [ i ]
e s t a r =cumFact ( k )
p r i n t ’ ␣ a p p r o x i m a t i o n ␣ =%11.7 e ␣ a b s o l u t e ␣ e r r o r ␣ =%11.7 e ␣ ␣ r e l a t i v e ␣ e r r o r =%11.7 e ’ \
% ( estar , abs_error (e , estar ) , rel_error (e , estar ))

Approximation Absolute error Relative error


2.7083333e+00 9.9484951e-03 3.6598468e-03
2.7182815e+00 3.0288585e-07 1.1142548e-07

11. Let
x cos x − sin x
f (x) = .
x − sin x
(a) Find limx→0 f (x).

9
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014

(b) Use four-digit rounding arithmetic to evaluate f (0.1).


(c) Replace each trigonometric function with its third Maclaurin polynomial, and repeat part
(b).
(d) The actual value of f (0.1) = −1.99899998. Find the relative error for the values obtained
in parts (b) and (c).

SOLUTION.

(a) Indeed, successive applications of L’Hospital’s rule make it plain that


x cos x − sin x −x sin x
lim = lim
x→0 x − sin x x→0 1 − cos x
− sin x − x cos x
= lim
x→0 sin x
−2 cos x + x sin x
= lim
x→0 cos x
−2 cos 0 + 0 · sin 0
=
cos 0
= −2.

15. Use the 64-bit long real format to find the decimal equivalent of the following floating-point
machine numbers.

(a) 0 10000001010 1001001100000000000000000000000000000000000000000000


(d) 0 01111111111 0101001100000000000000000000000000000000000000000001

SOLUTION. Recall that if we are given a machine number (binary number) of the form

s | c1 c2 · · · c11 | f1 f2 f3 · · · f52 ,
11 52
1 i
X X
11−i

with c = ci · 2 , and f = fi 2 , where, s, ci , fi ∈ {0, 1}, its corresponding floating-
i=1 i=1
points number (decimal) number takes the form:

(−1)s 2c−1023 (1 + f ).

Also, by the principle of mathematical induction we have the formulas


n  i  m−1  n
X 1 1 1
= − (2)
i=m
2 2 2
n
X
211−i = 212−m − 211−n (3)
i=m

10
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014

(a) For the machine number

0 10000001010 1001001100000000000000000000000000000000000000000000.

First, s = 0. Second, ci = 1 for all but c1 , c8 , c10 , thus;

c = c1 211−1 + c8 · 211−8 + c10 · 211−10


= 210 + 23 + 2
= 1024 + 8 + 2
= 1034.

Third, fi = 0 for all but f1 , f4 , f7 and f8 , hence;


 1  4  7  8
1 1 1 1
f = f1 + f4 + f7 + f8
2 2 2 2
1 1 1 1
= + + +
2 16 128 256
147
=
256
= 0.57421875.

Putting this altogether we obtain:

(−1)s 2c−1023 (1 + f ) = (−1)0 21034−1023 (1 + 0.57421875)


= 211 · 1.57421875
= 3224

(d) For the machine number

0 01111111111 0101001100000000000000000000000000000000000000000001

First, s = 0. Second, ci = 1 for all but c1 , thus by (3);


11
X
c= 211−i
i=2
12−2
=2 − 211−11
= 210 − 20
= 1023.

Third, fi = 0 for all but f2 , f4 , f7 , f8 and f52 , hence;


 2  4  7  8  52
1 1 1 1 1
f = f2 + f4 + f7 + f8 + f52
2 2 2 2 2
1 1 1 1 1
= + + + + 52
4 16 128 256 2
1460151441686529
=
4503599627370496
= 0.3242187500000002220446049250313080847263336181640625.

11
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014

Putting this altogether we obtain:

(−1)s 2c−1023 (1 + f ) = (−1)0 21023−1023 (1


+0.3242187500000002220446049250313080847263336181640625)
= 1.3242187500000002220446049250313080847263336181640625.

16. Find the next largest and smallest machine numbers in decimal form for the numbers given in
Exercise 15.

SOLUTION. Given a binary representation of a number, to get the next largest machine
number, i.e., increment by a factor of 1, moving from right to left, turn 1’s into 0’s until you
reach a 0. Turn that 0 into a 1. You’re done. Conversely, get the next smallest machine
number, decrement by a factor of 1, moving from right to left, turn 0’s into 1’s until you reach
a 1. Turn that 1 into a 0. You’re done.

(a) From the machine number

0 10000001010 1001001100000000000000000000000000000000000000000000.

we obtain the next smallest machine number

0 10000001010 1001001011111111111111111111111111111111111111111111.

First, s and c remain unchanged. Second, fi = 0 for all but f1 , f4 , f7 and fk , with k =
9, 10, . . . 52, hence; by (2);
 1  4  7 X 52  k
1 1 1 1
f = f1 + f4 + f7 +
2 2 2 k=9
2
 1  4  7  9−1  52
1 1 1 1 1
= f1 + f4 + f7 + −
2 2 2 2 2
1 1 1 1 1
= + + + +
2 16 128 256 252
2586051348529153
=
4503599627370496
= 0.5742187500000002220446049250313080847263336181640625

Putting this altogether we obtain:

(−1)s 2c−1023 (1 + f ) = (−1)0 21034−1023 (1


+0.5742187500000002220446049250313080847263336181640625)
= 211 · 1.5742187500000002220446049250313080847263336181640625
= 3224.00000000000045474735088646411895751953125

12
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014

(d) For the machine number

0 01111111111 0101001100000000000000000000000000000000000000000001

we obtain the next largest machine number

0 01111111111 0101001100000000000000000000000000000000000000000000.

First, s and c remain unchanged. Second, fi = 0 for all but f2 , f4 , f7 and f8 hence;
 2  4  7  8
1 1 1 1
f = f2 + f4 + f7 + f8
2 2 2 2
1 1 1 1
= + + +
4 16 128 256
83
=
256
= 0.32421875.

Putting this altogether we obtain:

(−1)s 2c−1023 (1 + f ) = (−1)0 21023−1023 (1 + 0.0.32421875)


= 1.32421875.

17. Suppose two points (x0 , y0 ) and (x1 , y1 ) are on a straight line with y1 = y0 . Two formulas are
available to find the x-intercept of the line:
x0 y1 − x1 y0 (x1 − x0 )y0
x= and x = x0 − .
y1 − y0 y1 − y0
(a) Show that both formulas are algebraically correct.
(b) Use the date (x0 , y0 ) = (1.31, 3.24) and (x1 , y1 ) = (1.93, 4.76) and three-digit rounding
arithmetic to compute the x-intercept both ways. Which method is better and why?

25. The binomial coefficient  


m m!
=
k k!(m − k)!
describes the number of ways of choosing a subset of k objects form a set of m elements.

(a) Suppose decimal machine numbers are of the form

± 0.d1 d2 d3 d4 × 10n , with 1 ≤ d1 ≤ 0, 0 ≤ di ≤ 9, if |n| ≤ 15.


i = 2, 3, 4 and
(4)
m

What is the largest value of m for which the binomial coefficient k can be computed
for all k by the definition without causing overflow?
(b) Show that mk can also be computed by


      
m m m−1 m−k +1
= ··· .
k k k −1 1

13
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014

m

(c) What is the largest value of m for which the binomial coefficient 3 can be computed
by the formula in part (b) without causing overflow?
(d) Use the equation in (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.

(a) First, note that the domain of the factorial function consists of non-negative integers, so

0 ≤ k ≤ m.

Second, the factorial function is strictly increasing, thus;

1 ≤ k! ≤ m! therefore, 1 ≤ (m − k)! ≤ m! (5)

From (5) we see that


1 ≤ k!(m − k)!,
which in turn makes it plain that
 
m m!
= ≤ m!,
k k!(m − k)!

so that m! is the largest numbered allocated during the calculation of mk , irrespective of




the value of k. From (4) it follows that the largest representable number must be

0.9999 × 1015 .

Therefore, it remains to identify an integer m0 such that

m0 ! ≤ 0.9999 × 1015 and (m0 + 1)! > 0.9999 × 1015 .

We use a program to evaluate the factorials and flag for overflow at each stage. The
python code is listed below:
from math i m p o r t f a c t o r i a l # O n l y i m p o r t what i s necessary

# Set the c o n s t a n t s
m=1
m _ f a c t o r i a l =m
maximum= 0 . 9 9 9 9 ∗ ( 1 0 ∗ ∗ ( 1 5 ) ) # The l a r g e s t r e p r e s e n t a b l e number

w h i l e m _ f a c t o r i a l < maximum :
m=m+ 1 ; # S e t t h e i n c r e m e n t
m _ f a c t o r i a l = f a c t o r i a l (m) # C a l c u l a t e t h e f a c t o r i a l

p r i n t " O v e r f l o w ␣ f o r ␣m␣=␣ " , m


p r i n t "The␣ l a r g e s t ␣ p o s s i b l e ␣ v a l u e ␣ o f ␣m␣=␣ " , m−1

14
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014

Our loop terminates with m = 18; the first number to overflow. Indeed, a direct calcula-
tion reveals that
17! = 0.355687428096 × 1015 and 18! = 0.6402373705728 × 1016 .
To conclude, m0 = 17 is the largest value that can be calculated without overflowing as
required.
(b) For m > k, a direct calculation makes it plain that
m(m − 1) · · · (m − k + 1)(m− (m(− − 1) · · · 
(
m! k)( k( (1)
  (( ( 
=
(m − k)! (m− (m(− − 1) · · · 
(
k)( k( (1)
 (( ( 

= m(m − 1) · · · (m − k − 1),
| {z }
k-many factors

hence;  
m m! m m − 1 m − k + 1
= = ··· , (6)
k k!(m − k)! k k −1 1
as required
(c) By the equality established in (6), we obtain that
     
m m m−1 m−2
= . (7)
3 3 2 1
By the same line of thought presented in part (a), it remains to find m0 such that
   
m0 15 m0 + 1
≤ 0.9999 × 10 and > 0.9999 × 1015 .
3 3
A direct computation reveals that
   
m m m! m!
+ = +
k k −1 k!(m − k)! (k − 1)!(m − k + 1)!
m!(m − k + 1) km!
= +
k!(m + 1 − k)! k!(m + 1 − k)!
(m + 1 − k + k)m!
=
k!(m + 1 − k)!
(m + 1)!
=
k!(m + 1 − k)!
 
m+1
=
k
Another application of (6) makes it plain that
     
m+1 m m
= +
3 3 2
m m − 1 m − 2 m m − 1
= +
3 2 1 2 1
1
= m(m2 − 1)
6
By method of bisection (introduced later in the course) we find that m = 181707.

15
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014

(d) By the equality established in (6), we obtain that


       
m m m−1 m−2 m−3 m−4
=
5 5 4 3 2 1
1
= (m − 4)(m − 3)(m − 2)(m − 1)m.
120
By method of 4-digit chopping arithmetic we obtain: 2597000. The rest of the calculations
are routine and we omit the details.


16

You might also like