Math 104A HW 01 Solution Key: 1.1 Review of Calculus
Math 104A HW 01 Solution Key: 1.1 Review of Calculus
(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.
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
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.
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)
2
1.1 Review of Calculus Solutions by Jon Lo Kim Lin - Fall 2014
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.
3
1.1 Review of Calculus Solutions by Jon Lo Kim Lin - Fall 2014
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
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,
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
4
1.1 Review of Calculus Solutions by Jon Lo Kim Lin - Fall 2014
(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
5
1.1 Review of Calculus Solutions by Jon Lo Kim Lin - Fall 2014
6
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014
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 .
7π
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.
(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
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 ,
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.
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
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 ))
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
SOLUTION.
15. Use the 64-bit long real format to find the decimal equivalent of the following floating-point
machine numbers.
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 ).
10
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014
0 10000001010 1001001100000000000000000000000000000000000000000000.
0 01111111111 0101001100000000000000000000000000000000000000000001
11
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014
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.
0 10000001010 1001001100000000000000000000000000000000000000000000.
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
12
1.2 Round-off Errors and Computer Arithmetic Solutions by Jon Lo Kim Lin - Fall 2014
0 01111111111 0101001100000000000000000000000000000000000000000001
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.
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?
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.
the value of k. From (4) it follows that the largest representable number must be
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
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
16