gauss4.f90

I suggest you either typed  this as it appears into the compiler, or as an easier way, just copy and paste it!

Note: I do not claim the program will 100% work, but I give it my best. If it doesn't, try tweaking it yourself, or email me about it, and I'll modify and post the improved version later. Good luck!

program gaussian_elimination_proper
!use linear_equations
implicit none
!defines coefficient and solve them


!allocatable array for coefficients
integer, allocatable, dimension(:,:) ::a
!real, allocatable, dimension(:) ::b
!size of array
integer::n
!loop variables and error flag
integer::i,j,error

!get size of prob
print*, "how many equations are there?"
read*, n

!allocate arrays
allocate(a(n,n+1))

!get corfficients
print*, "type coefficients for each equation in turn"
do i=1,n
read*, (a(i,j), j=1,n+1)
end do

!attempt to solve system of equations
!call gaussian_solve(a,b,error)

!check to see if there were any errors
!if (error<=-1 .and. error >=-3) then
!print*, "error in call to gaussian_solve"
!else if (error==-4) then
!print*, "system is degenerate"
!else
!print*, ""
print*, "solution is"
!print '(1X, "x("i2,")=",f6.2)', (i,b(i),i=1,n)
!end if
do i=1,n
print*, a(i,1:n+1)
end do
end program gaussian_elimination_proper


do i=1,n+1
do j=i+1,n
m=a(j,i)/a(i,i)
a(j,:)=a(j,:)-m*a(i,:)
end do
end do