Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Homework 1 Problem with Solutions - Numerical Computing | MATH 4800, Assignments of Mathematics

Material Type: Assignment; Class: NUMERICAL COMPUTING; Subject: Mathematics; University: Rensselaer Polytechnic Institute; Term: Summer 2010;

Typology: Assignments

2011/2012

Uploaded on 02/17/2012

koofers-user-rc6-1
koofers-user-rc6-1 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Numerical Computing Summer ’10 MATH/CSCI 4800-01
Homework-1
Assigned Tuesday July 6, 2010
Due Tuesday July 13, 2010
PROBLEMS
1. (Pencil-and-paper) Text page 8, Exercises 0.2, Problem 4(g).
We are asked to convert the binary x= (10.0101101)2into a decimal number. (The subscript 2
denotes binary representation. We shall omit this subscript when writing a decimal representation.)
We shall consider the integer and fractional parts separately. The integer part is easily seen to be
I= (10)2= 21= 2.
The fractional part is
F= (0.0101101)2.
The overbar notation denotes infinite repetition of the digits under the overbar. Thus, for example,
q= (.1101)2=.(1101 1101 1101 . . .)2.(1.1)
Now we can write
F= (.0101101)2
=y+z
where
y= (.010)2= 22= 0.25
and
z= (.0001101)2= (23)×(.1101)2= 23q
where qwas defined above in (1.1). To obtain the decimal representation of q, note from (1.1) that
24q= 1101.1101 = 23+ 22+ 20+q,
or,
16q= 13 + q
whence
q=13
15.
With qknown,
z=q
8=13
120 = 0.1083333333 . . . ,
and then,
F=y+z=.3583333333 . . . .
Finally, x=I+F= 2.3583333333. . . .
pf3
pf4
pf5

Partial preview of the text

Download Homework 1 Problem with Solutions - Numerical Computing | MATH 4800 and more Assignments Mathematics in PDF only on Docsity!

Numerical Computing Summer ’10 MATH/CSCI 4800- Homework-

Assigned Tuesday July 6, 2010 Due Tuesday July 13, 2010

PROBLEMS

  1. (Pencil-and-paper) Text page 8, Exercises 0.2, Problem 4(g). We are asked to convert the binary x = (10.0101101) 2 into a decimal number. (The subscript 2 denotes binary representation. We shall omit this subscript when writing a decimal representation.) We shall consider the integer and fractional parts separately. The integer part is easily seen to be

I = (10) 2 = 2^1 = 2.

The fractional part is F = (0.0101101) 2. The overbar notation denotes infinite repetition of the digits under the overbar. Thus, for example,

q = (.1101) 2 = .(1101 1101 1101.. .) 2. (1.1)

Now we can write

F = (.0101101) 2 = y + z

where y = (.010) 2 = 2−^2 = 0. 25 and z = (.0001101) 2 = (2−^3 ) × (.1101) 2 = 2−^3 q where q was defined above in (1.1). To obtain the decimal representation of q, note from (1.1) that

24 q = 1101.1101 = 2^3 + 2^2 + 2^0 + q,

or, 16 q = 13 + q whence q =

With q known, z =

q 8

and then, F = y + z =. 3583333333.... Finally, x = I + F = 2. 3583333333....

  1. (Pencil-and-paper) Text page 15, Exercises 0.3, Problem 2(d). Use IEEE single-precision arithmetic. Find the rounding error and show that it is smaller than 12 mach. We have x =

The integer part 6 has the binary representation (110) 2. For the fractional part 2/7 the binary repre- sentation is found as follows. Multiply by 2 and record the integer part:

2 7

× 2 =

× 2 =

× 2 =

× 2 =

We see that the pattern has begun to repeat. Therefore the binary representation of 2/7 is

2 7

Combining the results above, 44 7

or, in the standard normalized form,

44 7

= (1.10010) 2 × 22.

Now consider the IEEE single-precision system, which has 24-bit precision, i.e., there are 23 digits following the binary point or radix. Writing out in detail,

x =

where we have included 23 digits following the radix within curly brackets. Now we round to nearest. Since the first digit outside the curly brackets is 0, we simply chop to get

fl(x) = (1.10 010 010 010 010 010 010 010) 2.

In this procedure we have discarded (.010)2−^23. We know from above that (.010) = 2/ 7. Therefore,

fl

× 2 −^23.

Recall that for IEEE single-precision, mach = 2−^23. Therefore for x = 44/ 7 , the relative rounding error is given by (^) ∣ ∣ ∣ ∣

fl(x) − x x

× 2 −^23 ×

× 2 −^23 <

mach.

  1. (Pencil-and-paper)

(a) Solve the equation x^2 − 26 x + 1 = 0 by using the quadratic formula. Use 5-digit decimal arithmetic to find numerical values for the roots; for example, use

168 ≈ 12. 961. Identify any loss-of-significance error that you encounter. (b) Find both roots accurately by using only 5-digit arithmetic.

(d) For high sensitivity the condition number is large. Here, that appears to happen when sin x is near zero. But sin x is the function value, and when that is near zero the relative output error is undefined. In such a case the absolute rather than the relative condition number is relevant. It is given by

Absolute Condition number κA =

Absolute output error Absolute input error

=

sin(x + h) − sin x h

≈ | cos x|.

Since | cos x| ≤ 1 , the condition number is moderate and the problem is well-conditioned.

  1. (Pencil-and-paper) Suppose that sin x is approximated by P 2 n− 1 (x), its Taylor polynomial of degree 2 n − 1 centered at x = 0.

(a) Write down the expression for P 2 n− 1 (x). (b) How large should n be so that

| sin x − P 2 n− 1 (x)| ≤ 10 −^4

for all −π/ 2 ≤ x ≤ π/2? Check your result by evaluating the resulting P 2 n− 1 (x) at x = π/ 2.

Taylor’s formula with remainder for a function f (x) being expanded about x = x 0 is

f (x) = PN (x) + RN.

Here PN (x), the Taylor polynomial of degree N centered at x 0 , is given by

PN (x) = f (x 0 ) + (x − x 0 )f ′(x 0 ) +

(x − x 0 )^2 2!

f ′′(x 0 ) +

(x − x 0 )^3 3!

f ′′′(x 0 ) + · · · +

(x − x 0 )N N!

f (N^ )(x 0 ),

or, using summation notation, by

PN (x) =

∑^ N

k=

(x − x 0 )k k!

f (k)(x 0 ),

while the remainder is RN =

(x − x 0 )N^ + (N + 1)!

f (N^ +1)(c),

where c lies between x 0 and x but is otherwise unknown.

(a) In the problem under consideration, f (x) = sin x and x 0 = 0. Note that sin x, and all its even-order derivatives, vanish at x = 0, thereby ensuring that the Taylor polynomial of sin x is always of odd degree. Put another way, P 2 n− 1 is the same as P 2 n. Therefore, R 2 n− 1 is the same as R 2 n. Thus we can write

sin x = P 2 n− 1 (x) + R 2 n(x).

It is easily seen that for f (x) = sin x,

f (2p−1)(x) = (−1)p−^1 cos x and hence f (2p−1)(0) = (−1)p−^1.

Therefore

P 2 n− 1 (x) =

∑^ n

p=

x^2 p−^1 (2p − 1)!

f (2p−1)(0)

∑^ n

p=

(−1)p−^1

x^2 p−^1 (2p − 1)!

This is the desired expression for P 2 n− 1. As discussed above, the remainder is

R 2 n =

x^2 n+ (2n + 1)!

f (2n+1)(c) =

x^2 n+ (2n + 1)!

(−1)p+1^ cos c,

where c lies between 0 and x. (b) We need to find n so that the maximum value of R 2 n for x ∈ [−π/ 2 , π/2] does not exceed 10 −^4. Since | cos c| ≤ 1 , we have

|R 2 n| =

x^2 n+ (2n + 1)!

(−1)p+1^ cos c

(π/2)^2 n+ (2n + 1)!

A simple MATLAB calculation (see below) shows that n = 5 is the smallest value of n for which |R 2 n| ≤ 10 −^4.

format short e n=2: n =

2 3 4 5

F=(pi/2).^(2n+1)./factorial(2n+1)

F =

7.9693e-02 4.6818e-03 1.6044e-04 3.5988e- Correspondingly, the Taylor polynomial is

P 9 (x) =

∑^5

p=

(−1)p−^1 x^2 p−^1 (2p − 1)!

MATLAB shows that P 9 (π/2) = 1. 000003542584286. Since the exact answer for sin(π/2) is 1, the error is 3. 54258 × 10 −^6 < 10 −^4.

6. (MATLAB)

(a) Write a MATLAB script to generate the first 20 terms in the sequence defined by the difference equation xk+1 = 111 − (1130 − 3000 /xk− 1 )/xk, with x 1 = 11/ 2 and x 2 = 61/ 11. The exact solution is a monotonically increasing sequence converging to 6. (b) Explain your results, keeping in mind the notions of instability and ill-conditioning. You may wish to explore the effect of small changes in the values of x 1 and/or x 2.

(a) The script and the computed sequence are given below.

x(1)=11/2; x(2)=61/11; for k=2: x(k+1)=111-(1130-3000/x(k-1))/x(k); end

We see that the solution now approaches 100 quite rapidly. This is an indication of the high sensitivity of the solution to initial data, the sign of ill-conditioning.

Thus the mathematical problem is ill-conditioned and the numerical algorithm is unstable.