首页 > 解决方案 > The accuracy of fortran double precision

问题描述

I have this code when i create epsilons and then write them to a file with other values. The problem is that the values of epsilons i get in the file are not very close to the originals. Here is the code

open(unit=3,file='Avner_Yakov_4_q3.txt')
    v0 = 38 ! 85 mph
    t_max = x_max/v0;
    h = 0.1
    phi = pi/4
    write(3,*) 'calc  order    eps       delta-y      delta-z   mone-f'
    write(3,*) '------------------------------------------------------'
    eps1 = (/ 1d-1, 1d-3, 1d-5, 1d-7 /)
    do i=1,4
        r = solve_ball(h, t_max, eps1(i), v0, phi,'rk2')
        z_max(2) = r(3,ubound(r,2))
        y_max(2) = r(2,ubound(r,2))
        write(3,"(1i3,1i7,3E12.2,1i6)") i, 2, eps1(i), abs(y_max(2)-y_max(1)), abs(z_max(2)-z_max(1)), ubound(r,2)
     !deallocate (r)
    end do
    do i=1,4
        r = solve_ball(h, t_max, eps1(i), v0, phi,'rk3')
        z_max(2) = r(3,ubound(r,2))
        y_max(2) = r(2,ubound(r,2))
        write(3,"(1i3,1i7,3E12.2,1i6)") i+4, 3, eps1(i), abs(y_max(2)-y_max(1)), abs(z_max(2)-z_max(1)), ubound(r,2)
    !  deallocate (r)
    end do
    close(unit=3)

And the output

calc  order    eps       delta-y      delta-z   mone-f
 ------------------------------------------------------
  1      2    0.99E-01    0.14E-01    0.74E-01     5
  2      2    0.59E-03    0.19E-01    0.10E+00     7
  3      2    0.42E-05    0.91E-02    0.48E-01    50
  4      2    0.24E-07    0.61E-03    0.32E-02   476
  5      3    0.99E-01    0.34E-01    0.18E+00    28
  6      3    0.59E-03    0.24E-01    0.13E+00     8
  7      3    0.22E-05    0.77E-02    0.41E-01    10
  8      3    0.84E-08    0.45E-02    0.24E-01    50

标签: fortrandouble

解决方案


推荐阅读