JACOBI

 !Program name: JACOBI

Integer :: i, j, k, n

Real :: A(2,2), B(2)

Real :: X0(2), X(2), tol, norm, sigma

A(1,:)=[2,1]

A(2,:)=[5,7]

B=(/11,13/)

X0=(/1,1/)

k=0

tol=1.0E-06

10 do i=1,2

    sigma=0

    do j=1,2

      If (j .ne. i) sigma=sigma+A(i,j)*X0(j)

    end do

  X(i)=(B(i)-sigma)/A(i,i)

  end do

k=k+1

print *, k, (X(i), i=1,2)

norm=abs(X(1)-X0(1))

If (abs(X(2)-X0(2)) .gt. norm) then

norm=abs(X(2)-X0(2))

if (norm .lt. tol) go to 20

end if

do i=1,2

X0(i)=X(i)

end do

go to 10

20 stop

end

 

!THE FINAL RESULT IS:  k=32    7.1111107   -3.2222219

Comentários

Postagens mais visitadas deste blog

RECURSIVE

HYDROGEN-RADIAL

RUNGE-KUTTA