Homework/Programming 2. (Due Jan. 28)

advertisement
Homework/Programming 2. (Due Jan. 28)
Math. 639
(updated: January 20, 2014)
Problem 1. Write a function which inputs a matrix A in modified CRS
form, a right hand side b, an integer n and an initial iterate x0. The routine does one step of the Jacobi iteration producing a new vector x1. The
algorithm should look like:
for i=1:n
s=b(i)
for j in (1...n) such that A_ij not equal 0 and i not equal j
s=s-A_ij * x0(j);
end
x1(i)=s/A_ii;
end
Of course, you need to use the sparse structure to determine which indices
are included in the second for loop as well as the values of Aij . This routine
must work for general modified1 CRS storage for A as it will be used for
other matrices in later assignments.
Write a routine which sets up the modified CRS storage for A3 as a function of n. Here A3 is the tridiagonal matrix with twos on the diagonal and
minus one on the super and sub diagonal. This should be pretty simple as
every row except the first and last contain three simple entries while the first
and last only contain two.
Since the Jacobi method is linear, the convergence is determined by the
error behavior which is given by the formula ei+1 = Gei . Thus, to study the
error behavior of the method, we can solve a problem with right hand side
0 and initial iterate −ei . In this case, the iterate xi and the error are the
same vector (up to a sign) and so have the same norm.
Run the Jacobi method applied to A3 x = b for n = 4, 8, 16, 32, 64 with
initial iterate given by x0 = (1, 1, 1, . . . , 1)t and right hand side b = 0. This
you do by repetitively calling the one step routine. Report the number of
iterates required to reduce the relative error in k · k = (·, ·)1/2 by a factor of
1Modified CRS structure assumes that the diagonal entry is nonzero and stores it as
the first nonzero entry of any row.
1
2
.001, i.e., what is the first iterate k for which
kxk k
kek k
=
< .001?
ke0 k
kx0 k
Report the value of k as a function of n.
Download