

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


AMSC/CMSC 662/Fall 2004/Liu
Homework #1, due September 28
Objectives: (1) To warm up to programming with good habits, (2) To illustrate basic numerical ideas.
(1) Explore an ill conditioned matrix.
For this assignment you will need software that estimates the condition number of a matrix. This can be MATLAB, or a standard scientific subroutine package (e.g. NAG) or software from netlib. If you don’t have access to such software, you will have to skip part (a). If you don’t find a routine that estimates condition number but you can find one that computes the singular values or the singular value decomposition, the condition number is σmax/σmax. You can use svdcmp.f in Numerical Recipes, Section 2.9 or svd in MATLAB. For a fixed n, define A to be the n × n matrix with all entries zero except the aii = 1 and ai,i+1 = 2 for all i. That is, A has 1 on the diagonal and 2 immediately above the diagonal and all the rest zero. The determinant of this matrix is 1 and its norm is about 3 (depending on exactly which norm is used).
(a) Find the (estimated) condition number of A as a function of n for n = 2, 3 ,... until the condition number becomes (in the computer) infinite. (b) Let x ∈ Rn^ be the vector with n components whose components are given by xj = 1 if j is even and xj = 1/3 if j is odd. The value 1/3 is not stored exactly in the computer in floating point. Compute b = Ax by simple matrix multiplication. Now compute y by solving the equations Ay = b where b has just been computed. Write a program to do this in MATLAB, FORTRAN, C, or C++ using back substitution on an upper triangular matrix that is bidiagonal (see Kahaner, Moler, and Nash). Compute ‖x − y‖ for some norm and plot this as a function of n so long as possible. Compute |Ay − b| for the y you have and check its dependence on n. Comment on the contrast between this and the dependence of ‖x − y‖ on n. (c) Is the error ‖x − y‖ of the order predicted by the size of roundoff error (in single or double precision) and the condition number of A? Turn in a table or semi-log plot showing the error y − x, the residue Ay − b, and |y − x|/cond.
(2) Explore computer arithmetic and the problem of 0 · ∞.
The binomial coefficients, an,k, are defined by
an,k =
( n k
n! k!(n − k)!
To compute the an,k, for a given n, start with an, 0 = 1 and then use the recurrence relation an,k+1 = nk−+1k an,k.
(a) For a fixed of n, compute the an,k this way, noting the largest an,k and the accuracy with which an,n = 1 is computed. Do this in single and double precision. (b) Use the algorithm of part (a) to compute
E(n) =
2 n
∑n
k=
kan,k =
n 2
Write a program without any safeguards against overflow or zero divide (this time only!)^1. Show (both in single and double precision) that the computed answer has high accuracy as long as the intermediate results are within the range of floating point numbers. As with (a), explain how the computer gets an accurate, small, answer when the intermediate numbers have such a wide range of values. Why is cancellation not a problem? Turn in a table showing E(n), the relative error (E(n) − n/2)/(n/2), and an,n/ 2. For large n, one should be inf and the other NaN. Why? (c) To go beyond n ≈ 1000, we need a new method. We must avoid computing an,k and 2n separately. One way to do this is to use the recurrence relation for the largest terms, an,n/ 2. This is easiest when n = 2m is even. If we define
cm = 2−^2 ma 2 m,m (5)
then cm+1 = 2 m + 1 2 m + 2
cm. (6)
From this, and the known value of c 1 , we can compute all the cm. For even n, this gives us 2−nan,n/ 2. We can get the rest of the values of 2−nan,k needed for (4) by using either an,k+1 = nk−+1k an,k (if k > n/2) or an,k = (^) nk+1−k an,k+1 (if k < n/2). Show that this allows us to compute E(n) for n=10^4 , which would not be possible directly.
(^1) One of the purposes of the IEEE floating point standard was to allow a program with overflow or zero divide to run and print results