JACOBI-EIGEN

 ! Program name:JACOBI-EIGEN

real, allocatable :: A(:,:), O(:,:),OT(:,:), M(:,:)

real :: alfa

integer :: i, j, k, l

 

Print *, "Enter the dimension of the symmetric matrix A"

Read *, n

 

Allocate(A(n,n))

Allocate(O(n,n))

Allocate(OT(n,n))

Allocate(M(n,n))

 

Do i=1,n

   Do j=1,n

     Print *, 'A(',i,',',j,')= '

     Read *, A(i,j)

   End do

end do

do i=1,n

     write (*,*) (A(i,j),j=1,n)

end do

print *,

 

Do i=1,n

   Do j=1,n

   If (i .eq. j) O(i,j)=1

   if (i .ne. j) O(i,j)=0

   end do

end do

OT=transpose(O)

 

do i=1,n-1

do j=i+1,n

 

       alfa=0.5*atan(2*A(i,j)/(A(i,i)-A(j,j)))

 

       O(i,i)=cos(alfa)

       O(j,j)=cos(alfa)

       O(i,j)=-sin(alfa)

       O(j,i)=sin(alfa)

       OT(i,i)=cos(alfa)

       OT(j,j)=cos(alfa)

       OT(i,j)=sin(alfa)

       OT(j,i)=-sin(alfa)

 

      M=matmul(A,O)

      A=matmul(OT,M)

 

      Do k=1,n

        Do l=1,n

         If (k .eq. l) O(k,l)=1

         if (k .ne. l) O(k,l)=0

        end do

      end do

      OT=transpose(O)

 

    end do

end do

 

do i=1,n

         write (*,*) (A(i,j),j=1,n)

end do

print *

 

stop

end

Comentários

Postagens mais visitadas deste blog

RECURSIVE

HYDROGEN-RADIAL

RUNGE-KUTTA