Docsity

Numerical Methods Homework: Linear Algebra, Population Interpolation, Newton's Method - Pr, Assignments of Computer Science

Toggle sidebar
bg1
AMSC/CMSC 460-0201 Numerical Methods DUE Tuesday 03/10/09
HOMEWORK 1
Lecturer: H. Glaz Time: 2 PM !!
Instructions and Hints, etc: The purpose of Problem 1 is to get us started on linear algebra;
you should have just a brief (but nonempty) discussion of the results.
IMPORTANT: Problem 2 will be covered in class on Tuesday, March 03; there may be a hand-
written (so, NOT posted) handout. Note that the equation for the roundoff error (in terms of h) is
to be taken as known.
Please look on your MATLAB GUI and see if you have ‘demos.’ Or, can you otherwise find them?
I’d like to know in class Tuesday. Here, you might want to look at the basic matrix demo (including
‘hilb’). And, you probably want to see the Population demo.
Notice that the continuation of Problem 4 (at the bottom) is NOT part of the assignment, but will
be in the next one; it is a good idea to start the problem now.
(1) (10 pts) The Hilbert matrix of order n, Hn∈Rn×n, is defined by
(Hn)i,j =1
i+j−1.
Hnis nonsingular but the condition number of (Hn) (= κp(Hn), p = 1,2,∞) increases rapidly.
(x) (NO CREDIT ; DO NOT HAND IN). Take a few minutes to read about condition number
(for matrices); then run the following for practice and to get an idea what MATLAB can
do for you:
% -- You might want to run this interactively.
help hilb
type hilb
help invhilb
type invhilb
% -- notice the option for single precision above
A = hilb(7) % Suppress printout after seeing it & checking.
rcond(A)
cond(A)
1
pf3
pf4
pf5

Partial preview of the text

Download Numerical Methods Homework: Linear Algebra, Population Interpolation, Newton's Method - Pr and more Assignments Computer Science in PDF only on Docsity!

AMSC/CMSC 460-0201 Numerical Methods DUE Tuesday 03/10/

HOMEWORK 1

Lecturer: H. Glaz Time: 2 PM !!

Instructions and Hints, etc: The purpose of Problem 1 is to get us started on linear algebra; you should have just a brief (but nonempty) discussion of the results.

IMPORTANT: Problem 2 will be covered in class on Tuesday, March 03; there may be a hand- written (so, NOT posted) handout. Note that the equation for the roundoff error (in terms of h) is to be taken as known.

Please look on your MATLAB GUI and see if you have ‘demos.’ Or, can you otherwise find them? I’d like to know in class Tuesday. Here, you might want to look at the basic matrix demo (including ‘hilb’). And, you probably want to see the Population demo.

Notice that the continuation of Problem 4 (at the bottom) is NOT part of the assignment, but will be in the next one; it is a good idea to start the problem now.

(1) (10 pts) The Hilbert matrix of order n, Hn ∈ Rn×n, is defined by

(Hn)i,j = (^) i + j^1 − 1.

Hn is nonsingular but the condition number of (Hn) (= κp(Hn) , p = 1, 2 , ∞) increases rapidly.

(x) (NO CREDIT ; DO NOT HAND IN). Take a few minutes to read about condition number (for matrices); then run the following for practice and to get an idea what MATLAB can do for you:

% -- You might want to run this interactively.

help hilb type hilb help invhilb type invhilb

% -- notice the option for single precision above

A = hilb(7) % Suppress printout after seeing it & checking.

rcond(A) cond(A)

cond(A,1) cond(A,2) cond(A,’inf’) c = condest(A)

Ainv = invhilb(7)

format short; id = A*Ainv format long; id

% --- now try 8, 9, ...

Consider the problem Hnx(n)^ = e( 1 n ); e( 1 n )= (1, 0 ,... , 0)t^ , which has the explicit solution

x( jn )= (−1)

1+j (^) n(n + j − 1)! j!(j − 1)!(n − j)! , j^ = 1,... , n. where x( jn )is the jth component of the vector x(n)^ ; note that x(n)^ , e 1 ∈ Rn^. Use the Matlab ‘backslash solver’ with n = 2, 3 ,... , N and compare with the exact solution (given above); N is determined by finding when the solution has no significant digits – the main point of the problem. To be continued (after the break) ...

(2) (30 pts) Consider f 1 (x) = sin(x) at x = 1 , f 2 (x) = 10, 000 sin(x) at x = 1 , f 3 (x) = tan(x) at x = 1. 59 , and the derivative approximations

f ′(x) ≈ f^ (x^ +^ h h)^ −^ f^ (x),

f ′(x) ≈ f^ (x^ +^ h)^2 −h^ f^ (x^ −^ h),

f ′′(x) ≈ f^ (x^ +^ h)^ −^2 f h^ ( 2 x ) +^ f^ (x^ −^ h).

We analyzed the forward difference approximation for f ′(x) in class and found that the optimal h was proportional to ǫ^1 mach/^2 (more precisely, hopt = (4ǫmach|f (x)|/|f ′′(x)|).

(a) Estimate the 1st derivatives, using the forward difference approximation, for h = 10kǫ^1 mach/^2 with k = − 2 , − 1 , 0 , 1 , 2.

Year Data 1900 76,094, 1910 92,407, 1920 106,461, 1930 123,076, 1940 132,122, 1950 152,271, 1960 180,671, 1970 205,052, 1980 227,224, 1990 249,464, (a) Write an m-file which can (i) read the above data (or any like it) from an appropriately set up input file, (ii) form the Vandermonde matrix for the data (or any like it; use a general length n – the above set has n = 10 , but, e.g., one might want to use data from the referenced web site), and (iii) solve the resulting matrix problem for the coefficients of the interpolating polynomial. Hint: in MATLAB, try ‘help vander’ and help ‘load’. (b) Set up your input file with t 1 = 1900 etc. (notation is analogous to the text), execute your m-file and display the result. Additionally, compute the (estimated) condition number of the Vandermode matrix. (c) Evaluate the interpolating polynomial at t = 1999 and t = 2000. The web site above tells us that the population on July 1, 1999 was 272,690,813; on July 1, 2000 it was 275,130,000. Compare with your results. (d) Do the results for condition number and the comparison in part (c) make sense together? If so, why? If the comparison in part (c) is actually very good, then you should go to the web site and obtain other data (e.g., 1850 or so) and redo part (c) until you are certain that the reader(s) will be convinced that the poorly conditioned matrix leads to ‘errors’ in the coefficients of the interpolating polynomial (at least in the minimal sense that extrapolated results are largely useless). Note: Reader(s) include: TA/Grader and myself. (e) Follow the suggestion in Moler, 3.18 and get a much improved interpolating polynomial by a change of variables (centering and scaling in the language of the problem. (f) Verify that the new interpolant constructed in part (e) is better by comparing extrapolated results to data.

(4) (30 pts) Consider the equation

f (x) = 1 − x + 119 x^2 − 111 x^3 = 0. This equation has one real root, x∗^ ∼ 7 .7659512. If you wish, you can check this on your calculator/computer and, using calculus, verify that there are no other real roots.

For (c) – (f), write and use a Newton’s method mfile (i.e., subroutine with (preferably) function handles for f (x) and f ′(x) in the argument list) to obtain the necessary data. Near convergence, use format long and go to machine precision.

For (c) ONLY, use the code provided ALSO.

(a) (2 points) Explicitly write down Newton’s method for this equation. (b) (6 points) Take the initial guess x 0 = − 1 .0. Using exact arithmetic (i.e., no computer work), compute xk, k = 1, 2 , 3 , 4. From these results calculate x 325. (c) (8 points) Observe the computer output with x 0 = − 1 .0. Explain why the behavior is so different from that in (b). What is the behavior? Using the code below, you should focus on the gradual drift from the period 3 orbit due to floating point error. The discussion should be reasonably detailed.

clear all

fcubic = inline(’1 - x + (9/11)x^2 - (1/11)x^3’,’x’); fpr = inline(’-1 + (18/11)x - (3/11)x^2’ ,’x’);

%fiter=inline(’(-1+(9/11)x^2-(2/11)x^3)/(-1+(18/11)x-(3/11)x^2)’,’x’); %fiter=inline(’(-1 + (9/11)x^2 - (2/11)x^3) ... % /(-1 + (18/11)x - (3/11)x^2)’,’x’); fstring = ’(-1+ (9/11)x^2- (2/11)x^3)/(-1+(18/11)x-(3/11)x^2)’; fiter=inline(fstring , ’x’);

% ------------------------------------------------------------------

output1 = [ ]; output2 = [ ];

Niter = 60;

x0 = -1.0; x = x0; output1 = [output1 ; x0]; output2 = [output2 ; x0];

for i = 1:Niter x = x - fcubic(x)/fpr(x); output1 = [output1 ; x]; end

x = x0;