Homework 4

advertisement
Homework 4
Problem 1
Program Jacobi and Gauss-Seidel methods and test them on the following tri-diagonal
matrices:
1) The matrix A (n × n) is a tri-diagonal matrix with 20 on the main diagonal and −1
on sub- and super- diagonal (in matlab
A = 20 ∗ diag(ones(n, 1)) + (−1) ∗ diag(ones(n − 1, 1), 1) + (−1) ∗ diag(ones(n − 1, 1), −1)).
Take n = 100 and b = (1, . . . , 1)T . Take the initial guess x0 = (0, . . . , 0)T .
2) The matrix B (n × n) is a tri-diagonal matrix with 2.1 on the main diagonal and −1
on sub- and super- diagonal (in matlab
B = 2.1 ∗ diag(ones(n, 1)) + (−1) ∗ diag(ones(n − 1, 1), 1) + (−1) ∗ diag(ones(n − 1, 1), −1)).
Take n = 100 and b = (1, . . . , 1)T . Take the initial guess x0 = (0, . . . , 0)T
a) Compare the number of Jacobi iterations for matrices A and B.
b) Compare the number of Gauss-Seidel iterations for matrices A and B.
c) Compare the number of Jacobi and Gauss-Seidel iterations for matrix B.
Problem 2
Program conjugate gradient (CG) method and test it on the following example:
1) The matrix An (n × n) is a tri-diagonal matrix with 2 on the main diagonal and −1
on sub- and super- diagonal Take n = 50, 100, 150, 200, b = (1, . . . , 1)T and the initial guess
x0 = (0, . . . , 0)T . Report the number of iterations required for conjugate gradient method
to converge for each n (for example you can take stopping criteria as kb − Axk 2 ≤ 1e − 8).
Are the number of iterations proportional to n? Note that the condition number of these
matrices grow as n2 .
2) Compare the number of Gauss-Seidel and CG iterations for A50 .
3) Attempt to compare the number of Jacobi and CG iterations for A100 .
1
Download