0% found this document useful (0 votes)
77 views6 pages

Homework 2 Solved PDF

Francisco Quinga completed homework 2 which involved: 1) Proving that if a matrix A is strictly diagonally dominant, Gauss-Seidel iteration converges. 2) Generating a symmetric positive definite 5x5 matrix. 3) Implementing and comparing the Jacobi, Gauss-Seidel, and Conjugate Gradient methods for solving a sample linear system involving the generated matrix. Gauss-Seidel converged faster than Jacobi, requiring half as many iterations, while Conjugate Gradient performed better than Jacobi but not quite as well as Gauss-Seidel.

Uploaded by

Francisco Quinga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views6 pages

Homework 2 Solved PDF

Francisco Quinga completed homework 2 which involved: 1) Proving that if a matrix A is strictly diagonally dominant, Gauss-Seidel iteration converges. 2) Generating a symmetric positive definite 5x5 matrix. 3) Implementing and comparing the Jacobi, Gauss-Seidel, and Conjugate Gradient methods for solving a sample linear system involving the generated matrix. Gauss-Seidel converged faster than Jacobi, requiring half as many iterations, while Conjugate Gradient performed better than Jacobi but not quite as well as Gauss-Seidel.

Uploaded by

Francisco Quinga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Homework 2

Name: Francisco Quinga


1. Prove that if A is strictly diagonally dominant then the associated Gauss-Seidel iteration
converges.
Let the largest eigenvalue.
Let such that = .

Assume that | | = 1 and | | 1

=
( )1 =

= (D E)
Then for the m-row we have:

= ( )
> <

==> | ( )| | | | |
< > >

==> || ( | | | |) || |( )| ||
< < >

==> || (| | | |) | |
< >

==> || (| || | || | | ) | |
< >

==> || (| | | | ) | |
< >

>| |
==> ||
| | < | |

Since A is strictly diagonally dominant then: | | < | | > >| | , so


|| is less than one. Then:

( ) < 1
Which means that the Gauss-Seidel iteration converges.
2. Generate a symmetric positive definite matrix.
Using the generateSPDmatrix(n) algorithm for n=5 we get the following matrix:

a) Implement Jacobi method and compute the solution of the linear system.
function y=jacobi(A,b,x0,iter)
n=size(A,1);
for l=1:iter
y=zeros(n,1);
for i=1:n
%-----------sumatorio----------
suma=0;
for j=1:n
if j~=i
suma=suma+A(i,j)*x0(j);
end
end
%--------------------------------
y(i)=(b(i)-suma)/A(i,i);
end
x0=y;
end
end

4 0
If compute the solution for the linear system Ax=b were b=(32) and x0=(00), we get
5 0
3 0
the next solution for 3 iterations:
b) Implement Gauss-Seidel method and compute the solution of the linear system.
function x=seidel(A,b,xo,iter)
n=size(A,1);
for l=1:iter
x=xo;
for i=1:n
%-----------sumatorio----------
suma=0;
for j=1:n
if j~=i
suma=suma+A(i,j)*x(j);
end
end
%--------------------------------
x(i)=(b(i)-suma)/A(i,i);
end
xo=x;
end
end

4 0
If compute the solution for the linear system Ax=b were b=(32) and x0=(00), we get
5 0
3 0
the next solution for 3 iterations:
c) Compare a) and b). How much faster is Gauss-Seidel?
The following graph shows the logarithm in base 10 of the norm 2 of the error in each
iteration. Where the error of the k-th iteration is equal to:
= || ||

Fig 1. Jacobi vs Gauss-Seidel.

( ) ()
0.3590 0.1542
Table 1. Spectral radius of Jacobi and Gauss Seidel.
As we can see in the graph, Gauss-Seidel method converges faster than the Jacobi
method. In addition, the convergence factor of each method indicates that Gauss-Seidel
0.3590
is 0,1542 = 2,32 times faster.
d) Write down the numbers of iterations.
Jacobi iterations:
K=1 K=3 K=5 K=7 K=11 K=15

Gauss-Seidel iterations:
K=1 K=3 K=5 K=7 K=11 K=15

e) Implement Conjugate Gradient method and compute the solution of the linear
system.
function x= conjugrad(A,b,tol)
x=b-b;
r=b;
p=b;
while norm(r,2)>tol
z=A*p;
v=(r'*r)/(p'*A*p);
x=x+v*p;
temp=r;
r=r-v*z;
u=(r'*r)/(temp'*temp);
p=r-u*p;
end
end

4
If compute the solution for the linear system Ax=b were b=(32) , we get the next with a
5
3
tolerance of 0.1 solution:
f) Compare e) with a) and b).
The following graph shows the logarithm in base 10 of the norm 2 of the error in each
iteration. Where the error of the k-th iteration is equal to:
= || ||

Fig 2. Jacobi vs Gauss-Seidel vs Conjugate Gradient.

As we can see in the graph, the Gauss-Seidel method is still being faster than Jacobi and
Conjugate Gradient.

g) Write down the numbers of iterations.


Conjugate-Gradient iterations:
K=1 K=3 K=5 K=7 K=11 K=15

You might also like