Docsity

Assignment 1 with Supplement Solutions | Numerical Computing | MATH 4800, Assignments of Mathematics

Toggle sidebar
bg1
Numerical Computing F’05 A. Kapila
Assignment 1 - Supplement Solutions
PROBLEMS
1.
(a) To how many significant decimal digits do x=√10002 and y=√10001 agree?
(b) Assume a 10-digit decimal system with exponent range [−98,100].How many significant digits
are lost in performing the subtraction x−y?
(c) Explain how you would rearrange your computations to obtain a more accurate result.
(a) We have
x=√10002 = 1.000099995000500e+ 02,
y=√10001 = 1.000049998750062e+ 02
x−y= 4.999625043751621e−03,
x−y
x= 4.999125156229124e−05 <5×10−5.
Therefore, by definition (see page 45, equation (2.17) in the text), xand yagree to 4 digits.
(b) We see above that
z=x−y= (4.999625043751621) ×10−3.
In a ten-digit machine, assuming rounding to nearest, the above number would be computed as
ˆz= float(x)−float(y) = (1.000099995) ×102−(1.000049999) ×102= (4.999600000) ×10−3.
The last five digits above have been lost; the zeros are only placeholders.
(c) A better computational choice, for xand ynearly equal, would be to compute the difference as
x2−y2
x+y=1
√10002 + √10001.
This result turns out to be
˜z= 4.999625043 ×10−3
We see that ˜zis much closer to zabove than is ˆz. In fact, ˜zdiffers from
float(z) = (4.999625044) ×10−3
only in the last digit.
2. (a) Consider
R(x) = x4
4! −1
1 + ξ
for x∈[−1/2,1/2] and ξlying between 0 and x. Find an upper bound for |R|that is
independent of xand ξand is valid for all x∈[−1/2,1/2],
(b) Find a Taylor polynomial approximation p(x) for the function f(x) = ln(1 + x),centered at the
point x= 0 and accurate to within 10−6over the interval x∈[−1/2,1/2].Give appropriate
arguments about bounding the remainder that lead you to choose the degree nof the polynomial.
Use Matlab to construct two plots on [−1/2,1/2] : one that displays both f(x) and p(x),and
the other that displays |f(x)−p(x)|,and check if the error criterion is indeed satisfied.
pf3
pf4
pf5

Partial preview of the text

Download Assignment 1 with Supplement Solutions | Numerical Computing | MATH 4800 and more Assignments Mathematics in PDF only on Docsity!

Numerical Computing F’05 A. Kapila

Assignment 1 - Supplement Solutions

PROBLEMS

(a) To how many significant decimal digits do x =

10002 and y =

10001 agree?

(b) Assume a 10-digit decimal system with exponent range [− 98 , 100]. How many significant digits

are lost in performing the subtraction x − y?

(c) Explain how you would rearrange your computations to obtain a more accurate result.

(a) We have

x =

10002 = 1. 000099995000500 e + 02,

y =

10001 = 1. 000049998750062 e + 02

x − y = 4. 999625043751621 e − 03 ,

x − y

x

= 4. 999125156229124 e − 05 < 5 × 10

− 5 .

Therefore, by definition (see page 45, equation (2.17) in the text), x and y agree to 4 digits.

(b) We see above that

z = x − y = (4.999625043751621) × 10

− 3 .

In a ten-digit machine, assuming rounding to nearest, the above number would be computed as

zˆ = float(x) − float(y) = (1.000099995) × 10

2 − (1.000049999) × 10

2 = (4.999600000) × 10

− 3 .

The last five digits above have been lost; the zeros are only placeholders.

(c) A better computational choice, for x and y nearly equal, would be to compute the difference as

x

2 − y

2

x + y

This result turns out to be

z˜ = 4. 999625043 × 10

− 3

We see that ˜z is much closer to z above than is ˆz. In fact, ˜z differs from

float(z) = (4.999625044) × 10

− 3

only in the last digit.

  1. (a) Consider

R(x) =

x

4

1 + ξ

for x ∈ [− 1 / 2 , 1 /2] and ξ lying between 0 and x. Find an upper bound for |R| that is

independent of x and ξ and is valid for all x ∈ [− 1 / 2 , 1 /2],

(b) Find a Taylor polynomial approximation p(x) for the function f (x) = ln(1 + x), centered at the

point x = 0 and accurate to within 10

− 6 over the interval x ∈ [− 1 / 2 , 1 /2]. Give appropriate

arguments about bounding the remainder that lead you to choose the degree n of the polynomial.

Use Matlab to construct two plots on [− 1 / 2 , 1 /2] : one that displays both f (x) and p(x), and

the other that displays |f (x) − p(x)|, and check if the error criterion is indeed satisfied.

(a) We have

|R(x)| =

x 4

1 + ξ

|x|

4

1 + ξ

4

3

(b) We have

f (x) = ln(1 + x),

f

′ (x) = (1 + x)

− 1 ,

f

′′ (x) = (−1)(1 + x)

− 2 ,

f

′′′ (x) = (−1)

2 2!(1 + x)

− 3 ,

f (n)(x) = (−1)

n− 1 (n − 1)!(1 + x)

−n .

Therefore,

f (0) = 0 ,

f

′ (0) = 1 ,

f

′′ (0) = (−1),

f

′′′ (0) = (−1)

2 2!,

f

(n) (0) = (−1)

n− 1 (n − 1)!.

We get the Taylor polynomial of degree n and the remainder as

f (x) = pn(x) + Rn(x)

where

pn(x) = x −

x 2

n− 1 x n

n

, Rn(x) = (−1)

n x n+

n + 1

(1 + c) n+

where c(x) lies between o and x, and ultimately, both x and c lie in [− 1 / 2 , 1 /2]. For an error

tolerance , we must choose n so that the maximum value of |Rn| for x ∈ [− 1 / 2 , 1 /2] is smaller

than . Thus, we need

|Rn| ≤ , ∣ ∣ ∣ ∣

n x

n+

n + 1

(1 + c) n+

n+

(n + 1)(1 − 1 /2)n+^

n + 1

n ≥

So for  = 10

− 6 we shall need a very high n indeed. This is simply reflective of the fact

that estimates based on the remainder can sometimes be very crude indeed. For demonstration

purposes, let us take n = 16. The figure below gives the plots of f (x) and p 16 (x) and of the

difference |f (x) − p 16 (x)|. We see that the error is already within the required tolerance.

  1. A parachutist jumps out of a stationary hot air balloon. The parachutist’s velocity prior to the opening

of the chute is given by

v(t) =

gm

c

1 − e

−ct/m

where t = time, s

v = velocity, m/s

g = acceleration due to gravity, 9.81 m/s

2

m = mass of the parachutist, 68 kg

c = drag coefficient, 12.5 kg/s.

Write a Matlab program to compute v(t). Your output should be a labelled table of v(t) for times

t = 0, 1 , 2 , · · · 15 , and a labelled plot of v(t) on the same time interval. Does the plot make sense to

you? Comment.

See the Matlab log and the figure below. It appears that the velocity is heading towards a limiting

value, which is what one would expect to happen when drag balances gravity.

0 5 10 15

0

5

10

15

20

25

30

35

40

45

50

t

v

% script supp1.m

% Problem 2, supplement to HW 1

% Compares ln(1+x) with its Taylor polynomial of degree n

x=linspace(-1/2,1/2); % Define x

n=16;

p=x;

L=length(x);

term=ones(1,L);

% For loop for computing polynomial

for k=2:n

term=-term.*x;

p=p+(1/k)term.x;

end

plot(x,p,'r') % Plot polynomial

hold on

f=log(1+x);

plot(x,f,'bo') % Plot exact function

legend('Taylor polynomial','ln(1+x)')

figure

plot(x,(f-p),'b') % Plot error

legend('ln(1+x) - Taylor polynomial')