PROGRAM Gauss_Jordan
! Gauss Jordan method to find the solution of the system of linear equations
! The number of equations or the number of variables of the system
! of linear equations is n
! The coefficient matrix =a(ij) : i, j=1,2,3,...,n
! The constant vector =b(i) : i=1,2,3,...,n
! The vector of the variables =x(i) : i=1,2,3,...,n
integer::n,i,j,k,m
real:: a(5,5),b(5),x(5),r
open(3,file="input.dat")
open(4,file="output2")
read(3,*)n
do i=1,n
read(3,*)(a(i,j),j=1,n)
enddo
read(3,*)(b(j),j=1,n)
write(4,*) "a="
do i=1,n
write(4,*)(a(i,j),j=1,n)
enddo
write(4,*)" "
write(4,*)"b=",(b(j),j=1,n)
do k=1,n
do i=1,n
if(i/=k)then
r=a(i,k)/a(k,k)
do j=k,n
a(i,j+1)=a(i,j+1)-a(k,j+1)*r
enddo
b(i)=b(i)-b(k)*r
endif
enddo
enddo
do i=1,n
x(i)=b(i)/a(i,i)
enddo
write(4,*)" "
write(4,*)"The solution set is ","",(x(j),j=1,n),""
end PROGRAM
! Gauss Jordan method to find the solution of the system of linear equations
! The number of equations or the number of variables of the system
! of linear equations is n
! The coefficient matrix =a(ij) : i, j=1,2,3,...,n
! The constant vector =b(i) : i=1,2,3,...,n
! The vector of the variables =x(i) : i=1,2,3,...,n
integer::n,i,j,k,m
real:: a(5,5),b(5),x(5),r
open(3,file="input.dat")
open(4,file="output2")
read(3,*)n
do i=1,n
read(3,*)(a(i,j),j=1,n)
enddo
read(3,*)(b(j),j=1,n)
write(4,*) "a="
do i=1,n
write(4,*)(a(i,j),j=1,n)
enddo
write(4,*)" "
write(4,*)"b=",(b(j),j=1,n)
do k=1,n
do i=1,n
if(i/=k)then
r=a(i,k)/a(k,k)
do j=k,n
a(i,j+1)=a(i,j+1)-a(k,j+1)*r
enddo
b(i)=b(i)-b(k)*r
endif
enddo
enddo
do i=1,n
x(i)=b(i)/a(i,i)
enddo
write(4,*)" "
write(4,*)"The solution set is ","",(x(j),j=1,n),""
end PROGRAM
Comments
Post a Comment