matlab - Function returns different answers with same arguments -
i'm transitioning matlab fortran , encountering sorts of weird behaviors i'd never expect matlab. here's 1 that's got me puzzled:
program pruebanormal double precision :: g01eaf, x, y character :: t*1 integer :: iffail iffail = 0 t = 'l' x = 0.0 y = g01eaf('l',0.0,iffail) write(*,*) 'y = ',y end program pruebanormal
i have simple program in i'm trying find pdf @ x=0 of standard n(0,1) variable (should 0.5). g01eaf()
nag library function me. i'm using gfortran compile.
leaving rest of program unchanged, depending on how write arguments in g01eaf()
, different answers:
a) g01eaf(t,x,iffail) b) g01eaf(t,0.0,iffail) c) g01eaf(t,x,0)
now, under matlab, same (correct) answer either way: y = 0.500000. under fortran, however, get:
a) y = 0.500000 b) y = 1.000000 c) program received signal sigsegv: segmentation fault - invalid memory reference. backtrace error: #0 0xb766c163 #1 0xb766c800 #2 0xb77763ff #3 0x804982e in g01eafn_ violación de segmento (`core' generado)
i have no words answer in (b) , no clue (c) means.
the quick answer "wrong result" in
y = g01eaf('l',0.0,iffail)
you passing different type of real variable in
double precision x x = 0.0 ! x still double precision. y = g01eaf('l',x,iffail)
the function g01eaf
expects double precision: should read nag's documentation.
y = g01eaf('l', 0d0, iffail)
now elaborate.
you don't want these problems come often. want ensure interface available function call g01eaf
. compiler complain passing real of default kind function.
assuming have up-to-date version of library, want like
use nag_library, : g01eaf, nag_wp implicit none integer iffail real(kind=nag_wp) y y = g01eaf('l', 0._nag_wp, iffail) end
again, see documentation. both library, , meaning of modules, etc.
for older versions, 1 should still have module available, may called different, , nag_wp
may not defined (meaning must choose kinds).
the module lead complaint iffail
requires able set, must variable, not 0
. explains (c).
Comments
Post a Comment