Sympy computing the inverse laplace transform

11,062

Sympy assumes that w is complex-valued. The simpler approach is to provide the option real=True in the definition of the symbol.

s, t = sp.symbols('s, t')
w = sp.symbols('w', real = True)
expression = s/(s**2+w**2)

sympy.inverse_laplace_transform(expression, s, t)

cos(t*w)*Heaviside(t)

Share:
11,062

Related videos on Youtube

SomeRandomPhysicist
Author by

SomeRandomPhysicist

I am a physics PhD student at the University of Southampton working in the field of Quantum Optomechanics.

Updated on June 04, 2022

Comments

  • SomeRandomPhysicist
    SomeRandomPhysicist almost 2 years

    I am having some trouble computing the inverse laplace transform of a symbolic expression using sympy. In matlab and in the book I am working from the expression s/(s^2 + w^2) transforms to cos(wt).

    When I attempt to do this using sympy like so:

    expression = s/(s**2+w**2)
    Answer = sympy.inverse_laplace_transform(expression, s, t)
    

    I get that

    Answer = (-I*exp(2*t*im(w))*sin(t*re(w)) + exp(2*t*im(w))*cos(t*re(w)) + I*sin(t*re(w)) + cos(t*re(w)))*exp(-t*im(w))*Heaviside(t)/2
    

    What am I doing wrong?

  • chthonicdaemon
    chthonicdaemon over 7 years
    You can also do t = sp.Symbol('t', positive=True) if you don't want the Heaviside(t). Positive also implies real.