## Description

** Homework 1 Numerical Computation**

1. Execute the following lines in an interpreter (Matlab or Python).

>> format long

>> x = 9.4

>> y = x – 9

>> z = y – 0.4

What did you get for z? What should it be in exact arithmetic? Why is it not what it should

be? (Hint: For a detailed description, see Chapter 0.3.3 in Sauer’s Numerical Analysis.)

### 2. Consider the following two polynomials:

p1(x) = (x − 2)9

p2(x) = x

9 − 18x

8 + 144x

7 − 672x

6 + 2016x

5 − 4032x

4 + 5376x

3 − 4608x

2 + 2304x − 512

(1)

Convince yourself that p1(x) = p2(x) in exact arithmetic. (No need to show your work on this in

the write-up).

### Given a polynomial expressed as

p(x) = Xn

i=0

ai x

i

, (2)

Horner’s algorithm for evaluating the polynomial at some given x is: (i) initialize p = an, (ii) for

i = n − 1 down to 0, do p = p ∗ x + ai

. Implement Horner’s algorithm. (I’m using Matlab.)

Note that x = 2 is a root of p1(x) and p2(x). Generate 8000 equally spaced points in the interval

[1.92, 2.08].

(In Matlab, you can do this with linspace.) Evaluate and plot p1(x) at each point

in the interval. In a separate figure, evaluate and plot p2(x) using Horner’s algorithm. In exact

arithmetic, these should be the same.

What’s going on in these plots? (Hint: For a detailed

description, see Chapter 0.1 in Sauer’s Numerical Analysis or Chapter 1.4 and surrounding text

in Demmel’s Applied Numerical Linear Algebra.)

### 3. Consider the functions

f1(x) = 1 − cos(x)

sin2

(x)

, f2(x) = 1

1 + cos(x)

. (3)

Using trig identities, show that f1(x) = f2(x). (Please show your work on this one.) Implement

f1 and f2. Make a table of your implementations evaluated at the points xk = 10−k

for k =

0, 1, . . . , 12. You should see that f1 loses all accuracy as k increases (that is, as xk approaches

zero), while f2 retains its accuracy. Explain why.

#### Hint:

For a detailed description, see Chapter

0.4 in Sauer’s Numerical Analysis.)

1