File: /home/himanshu/fortran/gauss.f95 Page 1 of 2: Real Dimension Integer Logical
File: /home/himanshu/fortran/gauss.f95 Page 1 of 2: Real Dimension Integer Logical
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