PROGRAM Gauss_Jordan
!Gauss Jordan method to find the inverse of a matrix
!The order of the matrix is n.
!The coefficient matrix=a(i,j); i,j=1,2,3,...,n
integer::n,i,j,k,m
real:: a(10,10),r,t
open(4,file='output.dat')
print*,"Enter the order of the matrix:"
read(*,*)n
print*,"Enter the matrix:"
do i=1,n
read(*,*)(a(i,j),j=1,n)
enddo
write(4,*) "A="
do i=1,n
write(4,*)(a(i,j),j=1,n)
enddo
write(4,*)" "
do k=1,n
do m=1,n
if(m==k)then
a(m,n+1)=1.0
else
a(m,n+1)=0.0
endif
enddo
write(4,*) "aug=",k
do i=1,n
write(4,*)" ",(a(i,j),j=1,n+1)
enddo
write(4,*)" "
do i=1,n
if(i/=k)then
r=a(i,1)/a(k,1)
do j=1,n
a(i,j)=a(i,j+1)-a(k,j+1)*r
enddo
endif
enddo
t=a(k,1)
do m=1,n
a(k,m)=a(k,m+1)/t
enddo
enddo
write(4,*)" "
write(4,*) "inverse of A="
do i=1,n
write(4,*)(a(i,j),j=1,n)
enddo
end PROGRAM
!Gauss Jordan method to find the inverse of a matrix
!The order of the matrix is n.
!The coefficient matrix=a(i,j); i,j=1,2,3,...,n
integer::n,i,j,k,m
real:: a(10,10),r,t
open(4,file='output.dat')
print*,"Enter the order of the matrix:"
read(*,*)n
print*,"Enter the matrix:"
do i=1,n
read(*,*)(a(i,j),j=1,n)
enddo
write(4,*) "A="
do i=1,n
write(4,*)(a(i,j),j=1,n)
enddo
write(4,*)" "
do k=1,n
do m=1,n
if(m==k)then
a(m,n+1)=1.0
else
a(m,n+1)=0.0
endif
enddo
write(4,*) "aug=",k
do i=1,n
write(4,*)" ",(a(i,j),j=1,n+1)
enddo
write(4,*)" "
do i=1,n
if(i/=k)then
r=a(i,1)/a(k,1)
do j=1,n
a(i,j)=a(i,j+1)-a(k,j+1)*r
enddo
endif
enddo
t=a(k,1)
do m=1,n
a(k,m)=a(k,m+1)/t
enddo
enddo
write(4,*)" "
write(4,*) "inverse of A="
do i=1,n
write(4,*)(a(i,j),j=1,n)
enddo
end PROGRAM
Comments
Post a Comment