Docsity

Numerical Computing Assignment 1 Solutions: Taylor Polynomials and Approximations - Prof. , Assignments of Mathematics

Toggle sidebar
bg1
Numerical Computing F’05 A. Kapila
Assignment 1 Solutions
1. Section 1.1, page 9, problem 4.
The function f(x) = x1/3is not differentiable at x= 0 but possesses all derivatives at x= 1.
Therefore it does not have any Taylor polynomial at x= 0 but has Taylor polynomials of arbitrary
degree at x= 1.
2. Section 1.2, page 18, problem 2.
We have
f(x) = exsin x, f(0) = 0,
f0(x) = ex(sin x+ cos x), f 0(0) = 1,
f00(x)=2excos x, f00(0) = 2,
f000(x)=2ex(cos x−sin x).
The second-degree Taylor polynomial is
P2(x) = f(0) + xf0(0) + x2
2f00(0)
=x+x2.
The remainder is
R(x) = x3
6f000(c),
=x3
3ec(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, x3/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.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8
−0.4
−0.2
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
y=ex sin x
z=x+x2
|y−z|
π3/192
pf3
pf4
pf5

Partial preview of the text

Download Numerical Computing Assignment 1 Solutions: Taylor Polynomials and Approximations - Prof. and more Assignments Mathematics in PDF only on Docsity!

Numerical Computing F’05 A. Kapila Assignment 1 Solutions

  1. Section 1.1, page 9, problem 4. The function f (x) = x^1 /^3 is not differentiable at x = 0 but possesses all derivatives at x = 1. Therefore it does not have any Taylor polynomial at x = 0 but has Taylor polynomials of arbitrary degree at x = 1.
  2. Section 1.2, page 18, problem 2. We have f (x) = ex^ sin x, f (0) = 0, f ′(x) = ex(sin x + cos x), f ′(0) = 1, f ′′(x) = 2 ex^ cos x, f ′′(0) = 2, f ′′′(x) = 2 ex(cos x − sin x). The second-degree Taylor polynomial is

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].

  1. Section 1.2, page 19, problem 13.

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!

  • Rn,

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!)

]

+ R

n(n!)

+ R.

Here,

R =

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

|R| =

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)!}

< 10 −^6.

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

  1. Matlab Exercise. Write a function myfactorial that accepts a positive integer n as input and yields n! as output. You will need a while or a for loop to do the calculation. Use your function to compute the factorial of numbers from 1 to 15 and plot the results on a semilog plot. Your plot should be suitably labelled and titled. See attached Matlab log. The figure appears below.

(^100 5 10 ) 0

102

104

106

108

1010

1012

1014

n

n!

  1. (Extra credit) Study example 1.3.1 on page 25. Use a similar approach to solve problem 4, section 1.3, page 30.

9/17/05 8:55 AM /Users/ashkapila/HOME/COURSES/F05.../myfactorial.m 1 of 1

function r=myfactorial(n)

% input: positive integer n > 1

r=1;

% for loop for computing factorial

for k=2:n

r=r*k;

end