Syed Muhammad Kumail
Syed Muhammad Kumail

Reputation: 21

Floating point error in system of 4 equations using Gaussian Elimination in Fortran 90

This program is returning a "floating point error: overflow" with the following temperature values:

170 225 275 330 390 445 500 555 610 670 725 775 830 1100 1390 1670

Which is quite obvious, given the HUGE values that need to be raised up to the power 16 and then added.

This matrix represents a system of 4 equations that needs to be solved using Gaussian elimination for which have the remaining code ready.

Real Mat(4,4),Temp(10), Temp2(10),Sum

Do i=1,16
    Write(*,*)"enter Temperature value T",i
    Read (*,*) Temp(i)
End do

Do i=1,16
    Do j=1,16
        sum=0
        Do k=1,16
           if(i.GT.1)then
                l=(4*(i-1))+j
            elseif(i.eq.1)then
                l=i+j-1
            endif   
            Temp2(k)=Temp(k)**l
            sum=sum+Temp2(k)
        End do
        Mat(i,j)=Sum
    End do
End Do

Do I=1,4
  Write(*,*) (mat(I,J), j=1,4)
End do
 !this just forces the program to stay in the exe wind
    Read(*,*) sum
End    

Upvotes: 2

Views: 355

Answers (1)

Your array Temp is only 10 elements. You cannot read in 16 numbers. Mat is only (4,4) but you call it as (i,j) in loops 1..16 and 1..16.

Also, add implicit none, I would not consider a program without that for marking from my students.

I recommend you to use a compiler with good debugging features and set the correct flags. I use gfortran -g -fbacktrace -fcheck=all -Wall. g95 is also good. Also commercial NAG, which even checks for undefined values at runtime..

Upvotes: 5

Related Questions