



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!




Numerical Computing F’05 A. Kapila Assignment 1 Solutions
P 2 (x) = f (0) + xf ′(0) +
x^2 2
f ′′(0)
= x + x^2. The remainder is
R(x) = x^3 6
f ′′′(c),
x^3 3
ec(cos c − sin c),
where c(x) lies in the interval from 0 to x. For x ∈ [−π/ 4 , π/4], we also have c ∈ [−π/ 4 , π/4]. It is a simple matter to check (by differentiation) that ec(cos c − sin c) takes its maximum value in [−π/ 4 , π/4] at c = 0, and that this maximum equals 1. Also, x^3 /3 takes its maximum at π/ 4 , and it equals π^3 / 192. Thus, in [−π/ 4 , π/4], the remainder R(x) has the bound
|R| <
π^3 192
−0.4−0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.
−0.
0
1
y=ex^ sin x z=x+x^2 |y−z| π^3 /
The figure shows the graphs of y = ex^ sin x, the Taylor polynomial z = x + x^2 , the absolute error |y − z| and the bound π^3 / 192. It is clear that the error is indeed within the bound but approaches it at the ends of the interval [−π/ 4 , π/4].
We have f (x) =
ex^ − 1 x
The Taylor polynomial for f (x) can be constructed by using the formula
f (x) = f (0) + xf ′(0) +
x^2 2! f ′′(0) + · · · +
xn n!
where Rn is the remainder. However, we can be more succinct and use the known Taylor expansion of ex. Thus, ex^ = 1 + x +
x^2 2!
xn n!
xn+ (n + 1)!
ec,
where c lies between 0 and x. It is important to recognize that c is not a constant; its unknown position changes with x and as such, c = c(x). We can use the above expression to write
f (x) =
ex^ − 1 x
=
x
1 + x +
x^2 2!
xn n!
xn+ (n + 1)!
ec^ − 1
x 2!
xn−^1 n!
xn (n + 1)!
ec.
Upon integrating, ∫ (^1)
0
ex^ − 1 x
dx =
0
x 2!
xn−^1 n!
xn (n + 1)!
ec
dx
0
x + x^2 2(2!)
xn n(n!)
n(n!)
Here,
0
xn (n + 1)!
ec(x)^ dx.
We can bound the remainder by recognizing that for x ∈ [0, 1], c(x) ∈ [0, 1], and therefore, ec(x)^ ≤ e. Therefore, we can bound the remainder R as
0
xn (n + 1)!
ec(x)^ dx
< e
0
xn (n + 1)!
dx
= e
(n + 1){(n + 1)!}
To have an accuracy of 10−^6 , we must choose n so that
e
(n + 1){(n + 1)!}
Since the number x lies between 1 and 2, E must be zero and we only need to find the mantissa. Thus,
12 / 7 =
1 .d 1 d 2 d 3 d 4 d 5 d 6 d 7
2 = 1 +
d 1 2
d 2 22
d 7 (^27)
Subtract 1 and multiply by 2 to get
10 /7 = d 1 + d 2 2
d 7 (^26)
Since the LHS is greater than 1, we must choose d 1 = 1. Subtract 1 and multiply by 2 to get
6 /7 = d 2 +
d 3 2
d 7 25
Since the LHS is less than 1, we must choose d 2 = 0. Then multiply by 2 to get
12 /7 = d 3 + d 4 2
d 7 24
Since the LHS is greater than 1, we must choose d 3 = 1. Subtract 1 and multiply by 2 to get
10 /7 = d 4 +
d 5 2
d 7 23
Since the LHS is greater than 1, we must choose d 4 = 1. Subtract 1 and multiply by 2 to get
6 /7 = d 5 +
d 6 2
d 7 22
Since the LHS is less than 1, we must choose d 5 = 0. Then multiply by 2 to get
12 /7 = d 6 + d 7 2
Since the LHS is greater than 1, we must choose d 6 = 1. Subtract 1 and multiply by 2 to get
10 /7 = d 7.
We have arrived at the last digit, d 7. Since this equation is not satisfied by either d 7 = 0 or d 7 = 1, we cannot represent x = 12/7 exactly in the given 8-digit system. The closest we come to x is by selecting d 7 = 1. The result will be smaller than x and, in view of our calculations for the di above, is given by x^1 = (1.1011011) 2 = 1 +
The relative error is x − x^1 x
(^100 5 10 ) 0
102
104
106
108
1010
1012
1014
n
n!