Search code examples
pythonmpmath

How can I do a numerical inverse Laplace transform of a data array?


I would like to perform a numerical inverse Laplace transform on an array of data using Python.

I found an algorithm in mpmath called invertlaplace, however it accepts only lambda functions.


Solution

  • You could define a lambda that returns an interpolated version of your data.

    Something like:

    from math import floor, ceil
    data = [1,2,3,4,5]
    interp = lambda x: (1 - x%1)*data[floor(x)] + (x%1)*data[ceil(x)]
    

    I am unsure if the linear interpolation will be stable or not for the version of the inverse Laplace you are using, or for your data.