0% found this document useful (0 votes)
161 views2 pages

File: /home/himanshu/fortran/gauss.f95 Page 1 of 2: Real Dimension Integer Logical

The document describes a Fortran program that uses Gaussian elimination to solve a system of linear equations. It defines an array a with 41 rows and 42 columns to store the coefficients. It initializes some elements of a and then uses three subroutines - replace, strike, and norm - in a loop to transform a into reduced row echelon form and attempt to solve the system. If a solution is found, it writes the results to file 11, otherwise it prints an error message.

Uploaded by

Himanshu Gaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
161 views2 pages

File: /home/himanshu/fortran/gauss.f95 Page 1 of 2: Real Dimension Integer Logical

The document describes a Fortran program that uses Gaussian elimination to solve a system of linear equations. It defines an array a with 41 rows and 42 columns to store the coefficients. It initializes some elements of a and then uses three subroutines - replace, strike, and norm - in a loop to transform a into reduced row echelon form and attempt to solve the system. If a solution is found, it writes the results to file 11, otherwise it prints an error message.

Uploaded by

Himanshu Gaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

File: /home/himanshu/fortran/gauss.

f95 Page 1 of 2

program gauss
implicit none
real(8), dimension(41,42) :: a,b
integer :: i,j,k
logical :: lo;lo=.true.

a(1:41,1:42)=0
a(1,1)=1
a(1,42)=-0.5
a(41,41)=1
a(41,42)=log(2.0)
do i=2,40
a(i,i+1)=(0.025**(-2))+4*((1+0.025*(i-1))*0.025)**(-1)
a(i,i)=-2*(0.025)**(-2)-4*((1+0.025*(i-1))*0.025)**(-1)-2*(1+0.025*(i-1))**(-2)
a(i,i-1)=(0.025)**(-2)
end do

iloop: do i=1,41

jloop: do j=i,41
if(a(j,j).ne.0) then
exit jloop
end if
end do jloop

if (j.eq.42) then
print*,'no solution'
exit iloop
end if

if(j.ne.i) then
call replace(a,b,i,j)
end if

call strike(a,i)

do k=1,41
if(a(k,k).eq.0) then
lo=.false.
print*,"error"
end if
end do

if(lo) then
call norm(a)
end if
end do iloop

do i=1,41
write(11,*) (1+0.025*(i-1)), a(i,42)
end do

end program

subroutine replace(a,b,i,j)
real(8), dimension(41,42) :: a,b
integer i,j
b(1,1:42)=a(i,1:42)
a(i,1:42)=a(j,1:42)
a(j,1:42)=b(1,1:42)
end subroutine

subroutine strike(a,i)
real(8), dimension(41,42) :: a
integer i,j
do j=1,41
File: /home/himanshu/fortran/gauss.f95 Page 2 of 2

if (i.ne.j) then
a(j,1:42)=a(j,1:42)-(a(j,i)/a(i,i))*a(i,1:42)
end if
end do
end subroutine

subroutine norm(a)
real(8), dimension(41,42) :: a
integer i
do i=1,41
a(i,1:42)=a(i,1:42)/a(i,i)
end do
end subroutine

You might also like