Professional Documents
Culture Documents
Now to find xi ’s, one assumes an initial guess for the xi ’s and then uses the
rewritten equations to calculate the new estimates. Remember, one always
ϭ
uses the most recent estimates to calculate the next estimates, xi . At the end
of each iteration, one calculates the
absolute relative approximate error for each
xi as
Where new i x is the recently obtained value of xi , and old xi is the previous
value of xi . When the absolute relative approximate error for each xi is less
than the pre-specified tolerance, the iterations are stopped.
GAUSS-SEIDEL
SEIDEL CONVERGENCE THEOREM:
If A is diagonally dominant, then the Gauss-Seidel
Gauss method converges for any
starting vector x. A sufficient, but not necessary condition.
For all i
Example
Find the solution to the following system of equations using the Gauss-Seidel
Gauss
method.
Use x1=1 , x2=0 , and x3=1 as the initial guess and conduct two iterations.
Solution
The coefficient matrix
Ϯ
is diagonally dominant as
Iteration 1
The absolute relative approximate error at the end of the first iteration is
ϯ
The solution of equations obtained x1=0.99919 , x2=3.0001, and x3=4.0001
implicit none
integer,parameter::n=3
real,dimension(n,n)::a
real,dimension(n)::c
real,dimension(n)::x
sion(n)::x
integer::i,j ,iter ,k
real::old,sum,ea,es=0.00001,s
real::old,sum,ea,es=0.00001,sdummy
read(*,*)((a(i,j),j=1,n),i=1,n
read(*,*)((a(i,j),j=1,n),i=1,n)
read(*,*)(c(i),i=1,n)
read(*,*)(x(i),i=1,n)
do i=1,n ; s=0
do j=1,n
if(i.ne.j)s=s+abs(a(i,j
if(i.ne.j)s=s+abs(a(i,j))
enddo
if(abs(a(i,i)).lt.s)then
do i=1,n
ϰ
dummy=a(i,i)
do j=1,n
a(i,j)=a(i,j)/dummy
enddo ; c(i)=c(i)/dummy
enddo
iter=0 ; k=0
iter=iter+1
k=1
do i=1,n
old=x(i)
sum=c(i)
do j=1,n
if(i.ne.j)then
sum=sum-a(i,j)*x(j)
endif
enddo
x(i)=sum
print*,x(i)
if(ea.gt.es) k=0
enddo
print*, BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
enddo
end