Iterative Methods for Solving Linear Equations Page 4
coef(i,j) = x(i,j)/d
7 end do
c
c Because the Jacobi method solves for the unknown variable with
c respect to the current estimates of the other variables, the
c coefficient for the variable is made to be zero for subsequent
c use in the loop to compute the adjusted estimates
c
coef(i,i) = 0.d0
write(6,900)(x(i,j),j=1,nv+1)
10 end do
write(6,902)
do 13 i=1,no
write(6,900)(coef(i,j),j=1,nv+1)
13 end do
write(6,903)
15 iter = 0
c
c iterate is just a counter to keep track of the number of iterations
c
iterate = iterate+1
c
c Solve for the estimate of the unknown parameters
c
do 20 i=1,no
xnp(i) = coef(i,nv+1)
do 18 j=1,nv
xnp(i) = xnp(i) - coef(i,j)*xn(j)
18 end do
20 end do
c
c dx is a vector showing the change in the estimate of the variable
c with respect to the estimated value used in the previous iteration
c
do 50 i=1,no
dx(i) = xnp(i) - xn(i)
c
c Test to see if the change is greater than the threshold
c If it is, then the variable iter is made equal to 1
c At the beginning of each loop, this value is made equal to 0
c If iter is 1 then this means to iterate again
c
if (dabs(dx(i)).gt.0.01d0) iter = 1
c
c Update the estimated parameter value
c
xn(i) = xnp(i)
50 continue
write(6,904)iterate,(xn(i),i=1,nv),(dx(i),i=1,nv)
if (iter.gt.0) go to 15
900 FORMAT(5x,4(f10.4,5x))
901 FORMAT(15x,'SOLVING LINEAR EQUATION USING THE JACOBI ITER ATION MET
1HOD',//,'The coefficients to the equations with the solution at th
1e end are:',/)
902 FORMAT(//,'Rearranging the equations to solve for the unknown vari
1ables yields',/,5x,'the following coefficients: ',/)
903 FORMAT(//,'The estimated results after each iteration are shown as
1:'//,'Iteration',2x,'x(1)',9x,'x(2)',9x,'x(3)',7x,'dx(1)',7x,'dx(2
2)',7x,'dx(3)')
904 FORMAT(i3,4x,6(f10.5,2x))
stop
end