所以我试图学习,f2py并且我有以下Fortran代码
subroutine fibonacci(a, n)
implicit none
integer :: i, n
double precision :: a(n)
do i = 1, n
if (i .eq. 1) then
a(i) = 0d0
elseif (i .eq. 2) then
a(i) = 1d0
else
a(i) = a(i - 1) + a(i - 2)
endif
enddo
end subroutine fibonacci
Run Code Online (Sandbox Code Playgroud)
用f2py -c fibonacci.f -m fibonacciPython 编译并调用
subroutine fibonacci(a, n)
implicit none
integer :: i, n
double precision :: a(n)
do i = 1, n
if (i …Run Code Online (Sandbox Code Playgroud) 我试图通过指定 的参数来更精确地计算积分epsabs,scipy.integrate.quad假设我们正在将函数sin(x) / x^2从 1e-16 积分到 1.0
from scipy.integrate import quad
import numpy
integrand = lambda x: numpy.sin(x) / x ** 2
integral = quad(integrand, 1e-16, 1.0)
Run Code Online (Sandbox Code Playgroud)
这给了我们
(36.760078801255595, 0.01091187908038005)
Run Code Online (Sandbox Code Playgroud)
为了使结果更加精确,我们通过以下方式指定绝对误差容限epsabs
from scipy.integrate import quad
import numpy
integrand = lambda x: numpy.sin(x) / x ** 2
integral = quad(integrand, 1e-16, 1.0, epsabs = 1e-4)
Run Code Online (Sandbox Code Playgroud)
结果一模一样,误差还大到0.0109!我对参数的理解epsabs有误吗?我应该采取什么不同的措施来提高积分的精度?
我试图在 VS 代码中为 Fortran 代码添加垂直规则,如下所示
{
"[fortran]":
{
"editor.rulers": [0, 1, 5, 6, 79, 120]
},
}
Run Code Online (Sandbox Code Playgroud)
在 中settings.json,我能够使其适用于.f文件。但是,这些.f90文件没有任何垂直线。在我看来,语言标识符 [fortran]仅适用于 Fortran 77 代码,但我找不到 Fortran 90 代码的此类标识符的任何线索。有人可以向我指出吗?
顺便说一句,无论如何,我都需要 Fortran 90 的单独垂直规则设置,因为只有 Fortran 77 代码才需要四个前导垂直规则。
提前致谢!