I modified the fortran code to make sure that each numerical constant was double precision (added d+00 to each number). I also changed the atan function to datan. When I run the modified fortran code I obtain the following results.
FORTRAN
M**p = 5.170836889474639E-002
easy = 133.381005380000
atan term = -1.01175769856591
These results now match Python.
The modified fortran code is attached.
Chet
At 02:22 PM 6/8/2006, you wrote:
Hi,
I've added a very simply calculation to both the FORTRAN and Numeric calcs, and called it 'easy'. I've defined easy as --- easy = 5.11*5.234*4.987
the files are attached, and the output is below. The discrepancy always seems to show up at the 8th or 9th significant digit for simple multiplication, or for Numeric functions.
FORTRAN
M**p = 5.170837517496476E-002
easy = 133.381011962891
atan term = -1.01175767177248
PYTHON
M**p = 0.0517083688947
easy 133.38100538
atan term = -1.01175769857
Any diagnosis is greatly appreciated.
If anyone out there cares to run these 2 and verify the output on their machine, that would perhaps rule out/in the problem being my pc.
Buddy
From: [email protected] [mailto:[email protected] ] On Behalf Of Daniel Wheeler
Sent: Thursday, June 08, 2006 12:36 PM
To: Multiple recipients of list
Subject: Re: FiPy Precision
It depends on the size of the discrepancy. To diagnose this, we need a very simple calculation that
compares FORTRAN with Numeric for some very simple array manipulation (as Dan Lewis suggested).
On Jun 8, 2006, at 10:48 AM, Damm, Edward F. (E. Buddy) wrote:
Hello,
I'm getting some slight differences in some of my coefficients when comparing FiPy to Fortran benchmark code I'm using. I have confirmed that the equations are the same. There are some other potential areas that may be responsible for the discrepency, but I wonder if it may be due to precision.
I'm using Double Precision in the fortran code, and for any numbers in FiPy I am ending them in a decimal point and zero if it does not have values after the decimal, and of course anything that does have values after the decimal are input as such.
Is it reasonable to think that my descrepencies are due to precision? If so, do you have suggestions of how to reduce/eliminate the descrepancy?
Thanks
Buddy
This message and any attachments are intended for the individual or
entity named above. If you are not the intended recipient, please
do not forward, copy, print, use or disclose this communication to
others; also please notify the sender by replying to this message,
and then delete it from your system. The Timken Company / The
Timken Corporation
Daniel Wheeler
program DPTest1
implicit none
double precision R, T, term1, term2, term3, term4, easy
double precision pi, phi, C, RT, M, p, Mp
parameter(pi = 3.14159265358979d+00)
c --------------------------------------------------------
c Input
c --------------------------------------------------------
T = 923.15d+00
R = 8.314d+00
C =0.005d+00
phi = 0.5d+00
c --------------------------------------------------------
c calculation
c --------------------------------------------------------
RT = R*T
term1 = 0.02d+00*1.d-4*exp(-10115.0d+00/T)*exp(0.5898d+00
# *(1.0d+00+2.0d+00/pi*atan(14.985d+00-15309.0d+00/T)))
term2 = 4.529d-7*exp(-(1.0d+00/T-2.221d-4)*17767.0d+00)
term3 = term2/term1
term4 = (1.0d+00/T-2.221d-4)*26436.0d+00
M = term3*exp(C*term4)
p = phi**3*(10.0d+00 - 15.0d+00*phi + 6.0d+00*phi**2)
Mp = M**p
write(*,*) 'M**p = ', Mp
easy = 5.11d+00*5.234d+00*4.987d+00
write(*,*) 'easy =', easy
write(*,*), 'atan term = ', datan(14.985d+00-15309.0d+00/T)
end
