# Chapter 21 Laplace Transform¶

## Example 21.1.1, page no. 556¶

In [2]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
print laplace_transform(sympy.sin(2*t)*sympy.sin(3*t),t,s)

To find the laplace of given function in t
(12*s/((s**2 + 1)*(s**2 + 25)), 0, True)


## Example 21.1.2, page no. 557¶

In [14]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
print laplace_transform(sympy.cos(t**2),t,s)

To find the laplace of given function in t
(sqrt(pi)*(sqrt(2)*sin(s**2/4)*fresnelc(sqrt(2)*s/(2*sqrt(pi))) - sqrt(2)*cos(s**2/4)*fresnels(sqrt(2)*s/(2*sqrt(pi))) + cos(s**2/4 + pi/4))/2, 0, True)


## Example 21.1.3, page no. 558¶

In [15]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
print laplace_transform((sympy.sin(t**3)),t,s)

To find the laplace of given function in t
((-1)**(1/12)*pi*sqrt(s)*besseli(-1/3, 2*sqrt(3)*s**(3/2)*exp_polar(I*pi/4)/9)/18 + (-1)**(11/12)*sqrt(3)*pi*sqrt(s)*besseli(1/3, 2*sqrt(3)*s**(3/2)*exp_polar(I*pi/4)/9)/18 + (-1)**(7/12)*sqrt(3)*pi*sqrt(s)*besseli(5/3, 2*sqrt(3)*s**(3/2)*exp_polar(I*pi/4)/9)/18 - (-1)**(5/12)*pi*sqrt(s)*besseli(7/3, 2*sqrt(3)*s**(3/2)*exp_polar(I*pi/4)/9)/18 + (-1)**(1/12)*pi*sqrt(s)*besselj(-1/3, 2*sqrt(3)*s**(3/2)*exp_polar(I*pi/4)/9)/18 + (-1)**(11/12)*sqrt(3)*pi*sqrt(s)*besselj(1/3, 2*sqrt(3)*s**(3/2)*exp_polar(I*pi/4)/9)/18 + (-1)**(7/12)*sqrt(3)*pi*sqrt(s)*besselj(5/3, 2*sqrt(3)*s**(3/2)*exp_polar(I*pi/4)/9)/18 - (-1)**(5/12)*pi*sqrt(s)*besselj(7/3, 2*sqrt(3)*s**(3/2)*exp_polar(I*pi/4)/9)/18 + s**2*hyper((1,), (2/3, 5/6, 7/6, 4/3), -s**6/11664)/6 + (-1)**(1/3)*pi*besseli(2/3, 2*sqrt(3)*s**(3/2)*exp_polar(I*pi/4)/9)/(3*s) - 2*(-1)**(1/6)*sqrt(3)*pi*besseli(4/3, 2*sqrt(3)*s**(3/2)*exp_polar(I*pi/4)/9)/(9*s) - (-1)**(1/3)*pi*besselj(2/3, 2*sqrt(3)*s**(3/2)*exp_polar(I*pi/4)/9)/(3*s) + 2*(-1)**(1/6)*sqrt(3)*pi*besselj(4/3, 2*sqrt(3)*s**(3/2)*exp_polar(I*pi/4)/9)/(9*s), 0, True)


## Example 21.2.1, page no. 560¶

In [16]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = sympy.exp(-3*t)*(2*sympy.cos(5*t)-3*sympy.sin(5*t))
print laplace_transform(f,t,s)

To find the laplace of given function in t
((2*s - 9)/(s**2 + 6*s + 34), -3, True)


## Example 21.2.2, page no. 560¶

In [17]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = sympy.exp(3*t)*(sympy.sin(t))**2
print laplace_transform(f,t,s)

To find the laplace of given function in t
(2/((s - 3)*((s - 3)**2 + 4)), -oo, Abs(periodic_argument(exp_polar(2*I*pi)*polar_lift(-s + 3)**2, oo)) < pi)


## Example 21.2.3, page no. 561¶

In [41]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s

print 'To find the laplace of given function in t'
f = sympy.exp(4*t)*(sympy.cos(t)*sympy.sin(2*t))
print inverse_laplace_transform(f,t,s)

To find the laplace of given function in t
InverseLaplaceTransform(exp(4*t)*sin(2*t)*cos(t), t, s, _None)


## Example 21.4.1, page no. 563¶

In [26]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = t*sympy.sin(a*t)
print laplace_transform(f,t,s)

To find the laplace of given function in t
(2*a*s/(a**2 + s**2)**2, 0, Abs(periodic_argument(polar_lift(a)**2, oo)) == 0)


## Example 21.4.2, page no. 564¶

In [27]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = t*sympy.cos(a*t)
print laplace_transform(f,t,s)

To find the laplace of given function in t
((-a**2 + s**2)/(a**2 + s**2)**2, 0, Abs(periodic_argument(polar_lift(a)**2, oo)) == 0)


## Example 21.5, page no. 565¶

In [28]:
import sympy

t = sympy.Symbol('t')
s = sympy.Symbol('s')
u = sympy.Symbol('u')
f = sympy.integrate(sympy.exp(-s*t)*t/u,(t,0,u))+sympy.integrate(sympy.exp(-s*t),(t,u,sympy.oo))
print f

Piecewise((u/2, s**3*u**2 == 0), (1/(s**2*u) + (-s**2*u**2 - s*u)*exp(-s*u)/(s**3*u**2), True)) + Integral(exp(-s*t), (t, u, oo))


## Example 21.7, page no. 566¶

In [29]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = sympy.sin(a*t)/t
print laplace_transform(f,t,s)

To find the laplace of given function in t
(atan(a/s), 0, Abs(periodic_argument(polar_lift(a)**2, oo)) == 0)


## Example 21.8.1, page no. 567¶

In [30]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = t*sympy.cos(a*t)
print laplace_transform(f,t,s)

To find the laplace of given function in t
((-a**2 + s**2)/(a**2 + s**2)**2, 0, Abs(periodic_argument(polar_lift(a)**2, oo)) == 0)


## Example 21.8.2, page no. 568¶

In [31]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = (t**2)*sympy.sin(a*t)
print laplace_transform(f,t,s)

To find the laplace of given function in t
(2*a*(-a**2 + 3*s**2)/(a**2 + s**2)**3, 0, Abs(periodic_argument(polar_lift(a)**2, oo)) == 0)


## Example 21.8.3, page no. 569¶

In [32]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = sympy.exp(-3*t)*t**3;
print laplace_transform(f,t,s)

To find the laplace of given function in t
(6/(s + 3)**4, 0, True)


## Example 21.8.4, page no. 570¶

In [33]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = sympy.exp(-t)*t*sympy.sin(3*t)
print laplace_transform(f,t,s)

To find the laplace of given function in t
(6*(s + 1)/((s + 1)**2 + 9)**2, -1, True)


## Example 21.9.1, page no. 571¶

In [52]:
import sympy
from sympy.integrals import mellin_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = (1-t)/t
print mellin_transform(f,t,s)

To find the laplace of given function in t
-MellinTransform(1, t, s) + MellinTransform(1/t, t, s)


## Example 21.9.2, page no. 572¶

In [49]:
import sympy
from sympy.integrals import mellin_transform
from sympy.abc import t, s, a, b

print 'To find the laplace of given function in t'
f =(sympy.cos(a*t)-sympy.cos(b*t))/t
print mellin_transform(f,t,s)

To find the laplace of given function in t
(2**s*sqrt(pi)*a**(-s)*b**(-s)*(a*b**s - a**s*b)*gamma(s/2 - 1/2)/(4*gamma(-s/2 + 1)), (1, 2), And(Abs(periodic_argument(polar_lift(a)**2, oo)) == 0, Abs(periodic_argument(polar_lift(b)**2, oo)) == 0))


## Example 21.10.1, page no. 574¶

In [55]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the given integral find the laplace of tsin(t) and put s=2'
f = sympy.sin(t)*t
l = laplace_transform(f,t,s)
s = 2
print sympy.integrals.Integral(l)

To find the given integral find the laplace of tsin(t) and put s=2
Integral((2*s/(s**2 + 1)**2, 0, True), s)


## Example 21.10.3, page no. 575¶

In [57]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = sympy.integrate(sympy.exp(t)*sympy.sin(t)/t,(t,0,t))
l = laplace_transform(f,t,s)
print l

To find the laplace of given function in t
(sqrt(2)*LaplaceTransform(meijerg(((-1/2, 0, 1/4, 1/2, 3/4, 1), (1,)), ((), (-1/2, 0, 0)), 64*exp_polar(-4*I*pi)/t**4), t, s)/(8*sqrt(pi)) - 4/s - pi/(4*s) + 34*sqrt(2)/(9*s), 0, True)


## Example 21.11.1, page no. 576¶

In [58]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f =(s**2-3*s+4)/s**3
print inverse_laplace_transform(f,t,s)

To find the laplace of given function in t
InverseLaplaceTransform(1, t, s, _None)/s - 3*InverseLaplaceTransform(1, t, s, _None)/s**2 + 4*InverseLaplaceTransform(1, t, s, _None)/s**3


## Example 21.11.2, page no. 577¶

In [60]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f =(s+2)/(2*s**2-4*s+13)
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
s*InverseLaplaceTransform(1, t, s, _None)/(2*s**2 - 4*s + 13) + 2*InverseLaplaceTransform(1, t, s, _None)/(2*s**2 - 4*s + 13)


## Example 21.12.1, page no. 579¶

In [62]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f =((2*s**2-6*s+5)/(s**3-6*s**2+11*s-6))
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
2*s**2*InverseLaplaceTransform(1, t, s, _None)/(s**3 - 6*s**2 + 11*s - 6) - 6*s*InverseLaplaceTransform(1, t, s, _None)/(s**3 - 6*s**2 + 11*s - 6) + 5*InverseLaplaceTransform(1, t, s, _None)/(s**3 - 6*s**2 + 11*s - 6)


## Example 21.12. 3, page no. 579¶

In [63]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f =(4*s+5)/((s-1)**2*(s+2))
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
4*s*InverseLaplaceTransform(1, t, s, _None)/(s*(s - 1)**2 + 2*(s - 1)**2) + 5*InverseLaplaceTransform(1, t, s, _None)/(s*(s - 1)**2 + 2*(s - 1)**2)


## Example 21.13.1, page no. 580¶

In [64]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f =(5*s+3)/((s-1)*(s**2+2*s+5))
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
5*s*InverseLaplaceTransform(1, t, s, _None)/(s**3 + s**2 + 3*s - 5) + 3*InverseLaplaceTransform(1, t, s, _None)/(s**3 + s**2 + 3*s - 5)


## Example 21.13.2, page no. 581¶

In [65]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = s/(s**4+4*a**4)
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
s*InverseLaplaceTransform(1, t, s, _None)/(4*a**4 + s**4)


## Example 21.14.1, page no. 583¶

In [66]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = s**2/(s-2)**3
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
s**2*InverseLaplaceTransform(1, t, s, _None)/(s - 2)**3


## Example 21.14.2, page no. 583¶

In [67]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f =(s+3)/((s**2-4*s+13))
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
s*InverseLaplaceTransform(1, t, s, _None)/(s**2 - 4*s + 13) + 3*InverseLaplaceTransform(1, t, s, _None)/(s**2 - 4*s + 13)


## Example 21.15.1, page no. 584¶

In [68]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f =1/(s*(s**2+a**2))
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
InverseLaplaceTransform(1, t, s, _None)/(a**2*s + s**3)


## Example 21.15.2, page no. 584¶

In [69]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f =1/(s*(s+a)**3)
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
InverseLaplaceTransform(1, t, s, _None)/(s*(a + s)**3)


## Example 21.16.1, page no. 585¶

In [70]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = s/((s**2+a**2)**2)
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
s*InverseLaplaceTransform(1, t, s, _None)/(a**2 + s**2)**2


## Example 21.16.2, page no. 586¶

In [71]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = s**2/((s**2+a**2)**2) ;
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
s**2*InverseLaplaceTransform(1, t, s, _None)/(a**2 + s**2)**2


## Example 21.16.3, page no. 587¶

In [72]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = 1/((s**2+a**2)**2) ;
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
InverseLaplaceTransform(1, t, s, _None)/(a**2 + s**2)**2


## Example 21.17.1, page no. 588¶

In [73]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = (s+2)/(s**2*(s+1)*(s-2))
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
InverseLaplaceTransform(1, t, s, _None)/(a**2 + s**2)**2


## Example 21.17.2, page no. 589¶

In [74]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f =(s+2)/(s**2+4*s+5)**2
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
s*InverseLaplaceTransform(1, t, s, _None)/(s**2 + 4*s + 5)**2 + 2*InverseLaplaceTransform(1, t, s, _None)/(s**2 + 4*s + 5)**2


## Example 21.19.1, page no. 590¶

In [80]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = s/(s**2+a**2)**2
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
s*InverseLaplaceTransform(1, t, s, _None)/(a**2 + s**2)**2


## Example 21.19.2, page no. 591¶

In [76]:
import sympy
from sympy.integrals import inverse_laplace_transform
from sympy.abc import t, s, a

print 'To find the laplace of given function in t'
f = s**2/((s**2+a**2)*(s**2+b**2))
il = inverse_laplace_transform(f,t,s)
print il

To find the laplace of given function in t
s**2*InverseLaplaceTransform(1, t, s, _None)/(a**2*b**2 + a**2*s**2 + b**2*s**2 + s**4)


## Example 21.28.1, page no. 598¶

In [3]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

f = sympy.integrate(sympy.exp(-s*t)*(t-1),(t ,1 ,2))+sympy.integrate(sympy.exp(-s*t)*(3-t),(t ,2 ,3))
print 'Laplace of the given funtion is: '
print f

Laplace of the given funtion is:
Piecewise((1/2, s**3 == 0), (exp(-3*s)/s**2 - (-s**2 + s)*exp(-2*s)/s**3, True)) + Piecewise((1/2, s**3 == 0), (exp(-s)/s**2 + (-s**2 - s)*exp(-2*s)/s**3, True))


## Example 21.28.2, page no. 598¶

In [4]:
import sympy
from sympy.integrals import laplace_transform
from sympy.abc import t, s, a

f = sympy.integrate(sympy.exp(-s*t)*sympy.exp(-t),(t ,0 ,2))
print 'Laplace of the given funtion is: '
print f

Laplace of the given funtion is:
Piecewise((2, s == -1), (-1/(s*exp(2)*exp(2*s) + exp(2)*exp(2*s)) + 1/(s + 1), True))


## Example 21.34, page no. 602¶

In [7]:
import sympy, math

print 'To find the laplace transform of periodic funtion'
w = sympy.Symbol('w')
t = sympy.Symbol('t')
s = sympy.Symbol('s')
f = 1/(1-sympy.exp(-2*math.pi*s/w))*sympy.integrate(sympy.exp(-1*s*t)*sympy.sin(w*t),(t,0,math.pi))/w
print f

To find the laplace transform of periodic funtion
Piecewise((Piecewise((0, And(s == 0, w == 0)), (1.5707963267949*exp(3.14159265358979*I*w)*sin(3.14159265358979*w) + 1.5707963267949*I*exp(3.14159265358979*I*w)*cos(3.14159265358979*w) - I*exp(3.14159265358979*I*w)*sin(3.14159265358979*w)/(2*w), s == -I*w), (1.5707963267949*exp(-3.14159265358979*I*w)*sin(3.14159265358979*w) - 1.5707963267949*I*exp(-3.14159265358979*I*w)*cos(3.14159265358979*w) + I*exp(-3.14159265358979*I*w)*sin(3.14159265358979*w)/(2*w), s == I*w), (-s*sin(3.14159265358979*w)/(s**2*exp(3.14159265358979*s) + w**2*exp(3.14159265358979*s)) - w*cos(3.14159265358979*w)/(s**2*exp(3.14159265358979*s) + w**2*exp(3.14159265358979*s)), True)), And(Or(s == -I*w, s == 0, s == I*w), Or(s == -I*w, s == I*w, w == 0))), (Piecewise((w/(s**2 + w**2), And(s == 0, w == 0)), (w/(s**2 + w**2) + 1.5707963267949*exp(3.14159265358979*I*w)*sin(3.14159265358979*w) + 1.5707963267949*I*exp(3.14159265358979*I*w)*cos(3.14159265358979*w) - I*exp(3.14159265358979*I*w)*sin(3.14159265358979*w)/(2*w), s == -I*w), (w/(s**2 + w**2) + 1.5707963267949*exp(-3.14159265358979*I*w)*sin(3.14159265358979*w) - 1.5707963267949*I*exp(-3.14159265358979*I*w)*cos(3.14159265358979*w) + I*exp(-3.14159265358979*I*w)*sin(3.14159265358979*w)/(2*w), s == I*w), (-s*sin(3.14159265358979*w)/(s**2*exp(3.14159265358979*s) + w**2*exp(3.14159265358979*s)) - w*cos(3.14159265358979*w)/(s**2*exp(3.14159265358979*s) + w**2*exp(3.14159265358979*s)) + w/(s**2 + w**2), True)), True))/(w*(-exp(-6.28318530717959*s/w) + 1))