Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran 我的代码给了我10^-38左右的随机数,但我';我不使用任何随机函数_Fortran - Fatal编程技术网

Fortran 我的代码给了我10^-38左右的随机数,但我';我不使用任何随机函数

Fortran 我的代码给了我10^-38左右的随机数,但我';我不使用任何随机函数,fortran,Fortran,我通过Force 2.0使用Fortran 90,在windows 10下使用64位pc 我相信这可能是一个bug,因为我的同学使用了一个非常相似的代码,并且它对他们有效 这是我的代码: program integ implicit none real :: a_x , b_x , integ_1d, c a_x = 0 b_x = 1 c = integ_1d(a_x,b_x) write(*,*)c pause end program integ real function

我通过Force 2.0使用Fortran 90,在windows 10下使用64位pc

我相信这可能是一个bug,因为我的同学使用了一个非常相似的代码,并且它对他们有效

这是我的代码:

program integ
 implicit none
 real :: a_x , b_x , integ_1d, c
 a_x = 0
 b_x = 1
 c = integ_1d(a_x,b_x)
 write(*,*)c
 pause
end program integ

real function integ_1d (a_x , b_x)
 real :: x, f_x, pas
 real :: inte, a_x, b_x
 integer :: i
 integer , parameter :: npas=100
 pas=(b_x-a_x )/ npas
 inte =0.E0
 do i=0,npas-1
  x=a_x+( i*pas )
  inte=inte+ f_x
 end do
 integ_1d=inte*pas
end function integ_1d

real function f_x(x)
 real :: x
 f_x = x*x
end function f_x
它编译时没有任何问题,但总是给我不同的值,大约10^-38。例如:

1.75483065E-38
PAUSE
To resume execution, type go.  Other input will terminate the job.

使用完全相同的代码,使用相同的fortran版本在同一台计算机上编译


谢谢您的时间。

inte=inte+f_x
不是对函数
f_x
的引用,而是(未定义的)局部变量。你的意思可能是
inte=inte+f_x(x)
。非常感谢,先生,它现在工作得非常好!两个技巧:检查编译器文档,找到强制始终应用隐式none的选项。这样,编译器就会告诉您未定义的局部变量。此外,将函数/子例程放在一个模块中并“使用”该模块将捕获大量错误。@M.S.B.
implicit none
为什么会帮助编译器检测对未定义的局部(显式声明的类型)变量的引用?我同意使用
隐式无
,但我不认为它是万能的。@francescalus您是对的,局部变量是显式类型的,因此隐式无在这种情况下没有帮助。
1.16708418E-38
PAUSE
To resume execution, type go.  Other input will terminate the job.