Search the web
Sign In
New User? Sign Up
Fortran · Fortran Q/A's, info, lib and fans
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
numeric analysis   Message List  
Reply | Forward Message #446 of 516 |
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








Sat Sep 9, 2006 7:32 pm

oswaler
Online Now Online Now
Send Email Send Email

Forward
Message #446 of 516 |
Expand Messages Author Sort by Date

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...
Eric
oswaler
Online Now Send Email
Sep 10, 2006
6:54 pm

To avoid accumulation error, try dp (double precision) here....
student_gosset
Offline Send Email
Dec 19, 2007
6:44 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help