Tanh-Sinh Quadrature via F2PY – Part 3

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:

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:   

This entry was posted in Excel, Fortran, Link to Python, Maths, Newton, Numerical integration, NumPy and SciPy, UDFs, VBA and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.