viewing source code that shows how sympy.inverse_laplace_transform is calculated

36 views
Skip to first unread message

Stephen Salser

unread,
Sep 5, 2023, 1:47:28 PM9/5/23
to sympy
I would like to understand how sympy.inverse_laplace_transform is evaluated, so I attempted to view the source code.

When execute the command:

     print(inspect.getsource(sympy.inverse_laplace_transform))

I see the following source code which looks like is is almost all explanation.  (  I don't see the part that actually gets executed to calculate the inverse Laplace transform.   The part at the end where it says "return InverseLaplaceTransform(F, s, t, plane)" is just to return the symbolic expression of the integral if it fails to evaluate,  the part just before that doesn't make sense to me where it says: "return F.applyfunc(lambda Fij: inverse_laplace_transform(Fij, s, t, plane, **hints))  It doesn't make sense because it refers the the function itself rather than defining how the function should be calculated. )

Here is the source code for  sympy.inverse_laplace_transform:

def inverse_laplace_transform(F, s, t, plane=None, **hints): r""" Compute the inverse Laplace transform of `F(s)`, defined as .. math :: f(t) = \frac{1}{2\pi i} \int_{c-i\infty}^{c+i\infty} e^{st} F(s) \mathrm{d}s, for `c` so large that `F(s)` has no singularites in the half-plane `\operatorname{Re}(s) > c-\epsilon`. Explanation =========== The plane can be specified by argument ``plane``, but will be inferred if passed as None. Under certain regularity conditions, this recovers `f(t)` from its Laplace Transform `F(s)`, for non-negative `t`, and vice versa. If the integral cannot be computed in closed form, this function returns an unevaluated :class:`InverseLaplaceTransform` object. Note that this function will always assume `t` to be real, regardless of the SymPy assumption on `t`. For a description of possible hints, refer to the docstring of :func:`sympy.integrals.transforms.IntegralTransform.doit`. Examples ======== >>> from sympy import inverse_laplace_transform, exp, Symbol >>> from sympy.abc import s, t >>> a = Symbol('a', positive=True) >>> inverse_laplace_transform(exp(-a*s)/s, s, t) Heaviside(-a + t) See Also ======== laplace_transform, _fast_inverse_laplace hankel_transform, inverse_hankel_transform """ if isinstance(F, MatrixBase) and hasattr(F, 'applyfunc'): return F.applyfunc(lambda Fij: inverse_laplace_transform(Fij, s, t, plane, **hints)) return InverseLaplaceTransform(F, s, t, plane).doit(**hints)


Reply all
Reply to author
Forward
0 new messages