I am very new to FORTRAN and need to learn it quick. I wrote the
following code to find the definite integral of x^2 between 0 and 1
which should come out to 0.33333 etc. This same code with slight
syntax changes works in visual basic. When I run it in FORTRAN I
get .015625
The strange thing is if I try to make it less accurate by setting
dxval to 1000 and running the DO loop 1000 times I get a much more
accurate answer of .332828, running the same code in VB 1000 times
gives me .332833
I am guessing this has to do with a lack of understanding on my part
of how numbers are stored and calculated in FORTRAN variables but I
just can't find the mistake. I also tried converting dxval in the DO
loop to an integer with int(dxval) and still got the same result.
Here's the code. I am using a compiler called Plato3 and running it
under Windows XP.
PROGRAM ERIC
IMPLICIT NONE
real,parameter :: dxval=100000000.0,lower=0.0,upper=1.0
real :: dx,x,y
integer :: i
y=0.0
dx=(upper-lower)/dxval
x=0.0
DO i = 1,dxval, 1
y = y + ((x**2)*dx)
x = x + dx
END DO
write(*,*) y
END PROGRAM