DETERMINANT

 !program name:DETERMINANT

! Program for square matrices of order 2 or 3

!-----------------------------------

  Integer :: n,i,j

  real,dimension(:,:),allocatable :: A

  integer:: k,l,s

  integer:: nh,m

  real,dimension(:,:,:),allocatable::minor

  real,dimension(:),allocatable::det

  real :: lap_det

  Print *, 'Enter the dimension, n, of the square matrix A: '

  Read *, n

  Allocate ( A(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 *,

  allocate(minor(n,n-1,n-1))

 

   do k=1,n-1

     i=1+k

     do l=1,n-1

        j=1+l

        minor(1,k,l)=A(i,j)

     end do

   end do

 

   do k=1,n-1

      i=1+k

      j=1

      do l=1,n-1

         minor(2,k,l)=A(i,j)

         j=l+2

      end do

    end do

   

    do k=1,n-1

       i=1+k

       do l=1,n-1

          j=l

          minor(3,k,l)=A(i,j)

       end do

     end do

 

 

 do s=1,n

  Do k=1,n-1

     write (*,*) (minor(s,k,l),l=1,n-1)

  End do

  print *,

end do

 !-----------------------------------

allocate(det(n))

If(n==3) then

  do i=1,n

  det(i)= (minor(i,1,1)*minor(i,2,2))-(minor(i,1,2)*minor(i,2,1))

       print *, det(i)

  end do

else

   do i=1,n

       det(i)=minor(i,1,1)

   end do

end if

!---------------------------

 

  lap_det=0.

   do i=1,n

      m=i

      nh=m/2

       if(2*nh==m) then

       sign=-1

       else

      sign=1

      end if

      lap_det=lap_det+(sign*A(1,i))*det(i)

      print *, lap_det, 2*nh, sign

   end do

print *,

print *, lap_det

!--------------------------------------------------

stop

end

Comentários

Postagens mais visitadas deste blog

RECURSIVE

HYDROGEN-RADIAL

RUNGE-KUTTA