×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Help with numerical precision issue

Help with numerical precision issue

Help with numerical precision issue

(OP)
Hello. I need help to understand why my code is not giving me double numerical precision.
In this piece of code, I create a function that is analytically normalized, but when I calculate the numerical normalization factor, it seems to be with single precision. Here it is:

CODE --> fortran

program dyna
implicit none
integer i
integer, parameter :: Nq1=61
real(kind=8), parameter :: saw2au=1822.889950851334d0 
real(kind=8), parameter :: nitro=14.0067d0*saw2au 
real(kind=8), parameter :: mredu=nitro**2.0d0/(2.0d0*nitro)
real(kind=8) :: e0,pi,ch,x,x0,stepX,w,expo,c0,c1
complex(kind=8) :: soma,vec0(Nq1)
pi = 3.141592653589793d0
e0=0.005d0
x0=2.09970623d0 
stepX=0.01d0
w=2.d0*e0
c0 = ((mredu*w)/pi)**(1.d0/4.d0)
c1 = (4.d0/pi*(mredu*w)**3.d0)**(1.d0/4.d0)
do i=1,Nq1
  ch=(i-(Nq1-1.d0)/2.d0-1.d0)*stepX
  x=x0+ch 
  expo = dexp(-(x-x0)**2.d0*mredu*w/2.d0)
  vec0(i) = c0 * expo
end do
!----------------------------------------!
!normalizing                             !
soma=0.0d0                               !
do i=1,Nq1                               !
  soma=soma+conjg(vec0(i))*vec0(i)*stepX !
end do                                   !
vec0=vec0/sqrt(soma)                     !
!----------------------------------------!
write(*,'(a24,2(f23.15))')'normalization constant =',soma
end program 

I get 0.999998932390816, and it should be 1.0d0.
I use complex vectors because later in the code they will become complex.
I don't understand where is the problem. Can someone help me, please?
Thanks in advance,
Cayo

RE: Help with numerical precision issue

I think the problem is understanding what a precision of 15 digits means. This actually means 15 significant figures: not 15 decimal places. The bigger your number gets, the less decimal places you can expect.

For instance, if the biggest number in your calculations is 1000000 (7 digits) then you can only expect 8 decimal places of accuracy. That plus decimal/binary rounding will reduce the accuracy to about 6 decimal places.

RE: Help with numerical precision issue

Note how a simple operation can produce loss of digits:

I changed
mredu=nitro**2.0d0/(2.0d0*nitro)
to
mredu=nitro/2.0d0

normalization constant = 1.000000000000002 0.000000000000000

OPH. 2019-04-04 06:27

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close