For the last of the current series on combining Fortran, Python and Excel with F2PY and ExcelPython I have updated the xlSciPy spreadsheet to include two other variants of the Tanh-Sinh function:
- Quad_TSi integrates a non-periodic function over a semi-infinite interval (a to infinity)
- Quad_TSo integrates a periodic function over a semi-infinite interval
The new version can be downloaded from:
Download xlScipy.zip
and now includes all the Fortran source code (tsc.f90), as well as the compiled Fortran file, and Python and VBA code.
The Quad_TSi function input is the same as for Quad_TS, except that the limits range is replaced by a single value, a, the start of the integration interval.
The Quad_TSo function has an additional optional “omega” argument. For most functions use of the default value of 1 will give satisfactory results, but in some cases (such as Function 3 below) a different value will give greater precision with far fewer evaluations. I have not yet found any clear statement of how omega should be optimised, other than trial and error.
In modifying the original Fortran code to work with F2PY I found the following links very useful:
- Writing fast Fortran routines for Python
- Interfacing Python with Fortran
- f2py: Binding Fortran and Python
- Using Python and Fortran with F2PY
and for more information on the background to Tanh-Sinh Quadrature see:
Also, don’t forget the Tanh-Sinh Quadrature spreadsheets from Graeme Dennes posted here, which include VBA versions of all the functions presented here, and many more, together with examples of use in real applications: