Skip to content Skip to sidebar Skip to footer

Laplace Inverse In Python With Mpmath

I want to use 'DE HOOG' algorithm for numerical Laplace inverse transform. I want to use the 'mpmath' package and I installed it from the link: https://github.com/klkuhlm/mpmath Le

Solution 1:

The object InverseLaplaceTransform has an attribute degrees that dictates the levels of approximation necessary to achieve a given level of precision. Your copy of InverseLaplaceTransform updates degrees each time you call it with a smaller and smaller value. Eventually, degrees is so small the parameter fp has only one value, which is not enough to continue with further calculations.

Answer : edit your call to invlapdehoog to reset degrees each time. I suggest however calling invertlaplace directly rather than invlapdehoog.

for i in xrange(0,10):
    G.append(mp.invertlaplace(f, t[i], method = 'dehoog', degree = 18))

Edit: The original poster asked a related question in the comments to this solution. They asked why the computation time increases (quite drastically) with consecuitve calls to mp.invertlaplace. In short, the mp.invertlaplace is updating its attribute precision which dictates how many decimal places it should compute in calculating the inverse laplace. As with the above solution, we can pass in precision to each call to make sure we obtain the precision we want (eg - 10 decimal places):

for i in xrange(0,10):
    G.append(mp.invertlaplace(f, t[i], method = 'dehoog', dps = 10, degree = 18))

PS - you can apply the inverse laplace to all of t at once with the following snippet:

G = map( lambda x: mp.invertlaplace(f, x, method = 'dehoog', dps = 10, degree = 18), t)

Post a Comment for "Laplace Inverse In Python With Mpmath"