Starting from:
$30

$24

Numerical Computation Homework 1:


    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


(1)
p2(x) = x9
18x8 + 144x7    672x6 + 2016x5
4032x4 + 5376x3
4608x2





+ 2304x  512

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
n

Xi

p(x) =ai xi;
(2)
=0


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 gure, 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

1
cos(x)


1


f1(x) =


;
f2(x) =

:
(3)


sin2(x)


1 + cos(x)



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

More products