0

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Imaginary
  • 135
  • 1
  • 7

1 Answers1

1

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sgillen
  • 596
  • 2
  • 7
  • Thanks, I tried this but ivertlaplace doesn't like when interp uses the modulus operator and throws an error: -------TypeError: unsupported operand type(s) for %: 'mpc' and 'int' -------- If I try int(x), it throws the error: -----TypeError: int() argument must be a string or a number, not 'mpc' – Imaginary Aug 01 '19 at 21:49
  • It look like you can replace the built in modulus operator with mpmath.fmod described here: http://mpmath.org/doc/current/general.html – sgillen Aug 01 '19 at 22:18