Laplace Transformation
This tutorial contains many Mathematica scripts. You, as the user, are free to use all codes for your needs, and have the
right to distribute this tutorial and refer to this tutorial as long as
this tutorial is accredited appropriately. Any comments and/or contributions for this tutorial are welcome; you can send your remarks to <Vladimir_Dobrushkin@brown.edu>
Return to
computing page
Return to
computing page for the second course APMA0330
Return to
Mathematica tutorial for the first course
Return to
Mathematica tutorial for the second course
Return to the
main page for the course APMA0330
Return to the
main page for the course APMA0340
Contents
Part VI: Laplace Transformation
Laplace transform
Heaviside function
Laplace Transform of Discontinuous Functions
Inverse Laplace transformation
Laplace transformation in differential equations
Mechanical and Electrical Vibrations
Other applications
LaplaceTransform[t^4 Sin[t], t, lambda]
LaplaceTransform[HeavisideTheta[t - 1] t, t, lambda]
LaplaceTransform[DiracDelta[t], t, lambda]
LaplaceTransform[f''[t], t, lambda]
Out[4]= -lambda f[0] + lambda^2 LaplaceTransform[f[t], t, lambda] -
Derivative[1][f][0]
LaplaceTransform[If[t > Pi, Cos[t], t], t, s]
Out[4]= (E^(-\[Pi] s) (-1 + E^(\[Pi] s) - \[Pi] s - s^3/(1 + s^2)))/s^2
LaplaceTransform[UnitStep[2 Sin[t]], t, lambda]
Out[5]= E^(\[Pi] lambda)/((1 + E^(\[Pi] lambda)) lambda)
LaplaceTransform[ArcTan[t/a], t, s, Assumptions -> a > 0]
Out[5]= (2 CosIntegral[a s] Sin[a s] +
Cos[a s] (\[Pi] - 2 SinIntegral[a s]))/(2 s)
LaplaceTransform[y''[t] + 4 y[t] == 0, t, lambda]
Out[4]= 4 LaplaceTransform[y[t], t, lambda] +
lambda^2 LaplaceTransform[y[t], t, lambda] - lambda y[0] - Derivative[1][y][0] == 0
% /. {y[0] -> 1, y'[0] -> 2}
Out[5]= -2 - lambda + 4 LaplaceTransform[y[t], t, lambda] +
lambda^2 LaplaceTransform[y[t], t, lambda] == 0
Solve[%, LaplaceTransform[y[t], t, lambda]]
Out[6]= {{LaplaceTransform[y[t], t, lambda] -> (2 + lambda)/(4 + lambda^2)}}
InverseLaplaceTransform[%, lambda, t]
Out[7]= {{y[t] -> Cos[2 t] + Sin[2 t]}}
Now we give an example of application of the inverse Laplace transform.
InverseLaplaceTransform[4/s/(4 + s^2), s, t]
Out[8]= 4 (1/4 - 1/4 Cos[2 t])
Simplify[%]
Out[9]= 2 Sin[t]^2
Apart[4/s/(4 + s^2), s]
Out[10]= 1/s - s/(4 + s^2)
LaplaceTransform[2 Sin[t]^2, t, lambda]
Out[11]= 4/(lambda (4 + lambda^2))
I. How to define Heaviside functions
To define a function, just type in the formula. We need to use a special form for the left hand side, which includes an underscore after the name of the variable, and a special "colon-equals" sign for the function definition:
f[x_] := (Cos[x] -1)/ x^2
There is no output on this imput. To see it, type Print[f[x]] You can use this function with different arguments or obtain its numerical values:
f[2 x+1]
Out[2]= (Cos[2 x+1]-1)/(2 x+1)^2
N[f[1.5]]
Out[3]= -0.41306
The simplest user-defined functions are the "one-liners", where the quantity of interest can be computed by a single formula. However, in may cases, you may find it impossible to define the function's value in a single simple formula. Instead, you may need to carry out several steps of computation, using temporary variables. You may want several input values, and you may want the user to group some of those input values in curly brackets.
I. How to define functions
g[t_] = Piecewise[{{t, 0 < t < 1}, {(t - 2)^2, 1 < t < 2}, {6 - t^2,
2 < t}}]
LaplaceTransform[g[t], t, lambda]
Out[14]= (1/(lambda^3))E^(-2 lambda) (-4 - 4 lambda - E^lambda lambda +
E^(2 lambda) lambda + 2 lambda^2 - E^lambda lambda^2 +
Gamma[3, -lambda])
Shift Rule:
LaplaceTransform[UnitStep[t - 2]*Sin[t], t, lambda]
Out[5]= (E^(-2 lambda) (Cos[2] + lambda Sin[2]))/(1 + lambda^2)
LaplaceTransform[UnitStep[t - 2]*Sin[t - 2], t, lambda]
Out[6]= E^(-2 lambda)/(1 + lambda^2)
LaplaceTransform[DiracDelta[t - 2]*Sin[t - 2], t, lambda]
Out[7]= 0
LaplaceTransform[DiracDelta[t - 2]*Sin[t], t, lambda]
Out[8]= E^(-2 lambda) Sin[2]
I. Standard procedure
One of the methods to find inverse laplace transform is to us epartial fraction decomposition and then apply inverse Laplace transform to each term (usually using a table of given Laplace transforms). However, Mathematica allows one to find the inverse Laplace transform stright forward:
InverseLaplaceTransform[4/s/(4 + s^2), s, t]
Out[8]= 4 (1/4 - 1/4 Cos[2 t])
Simplify[%]
Out[9]= 2 Sin[t]^2
Apart[4/s/(4 + s^2), s]
Out[10]= 1/s - s/(4 + s^2)
LaplaceTransform[2 Sin[t]^2, t, lambda]
Out[11]= 4/(lambda (4 + lambda^2))
The general approach:
InverseLaplaceTransform[%, lambda, t]
Out[7]= {{y[t] -> Cos[2 t] + Sin[2 t]}}
II. Convolution rule
III. Residue method
Now we define the inverse Laplace transform using residue method, assuming that singular points are at most of multiplicity 3. It is applyied to the expression of the form: p(s)/q(s). The output is a collection of residues for each singular point.
(* use variable "s" to define p and q *)
Natalia[p_, q_] :=
(g = ToRules[Roots[q == 0, s]];
u = s /. {g};
h = Tally[u];
j = Length[r];
Res1 = {s - s0}*{p/{Factor[q, Extension -> I]}}*Exp[s*t];
Res2[s_] = {s - s0}^2*{p/{Factor[q, Extension -> I]}}*Exp[s*t];
Res3[s_] = {s - s0}^3*{p/{Factor[q, Extension -> I]}}*Exp[s*t];
r = Table[h[[i, 2]], {i, 1, Length[h]}];
Do[If[r[[i]] == 1, Res = Res1 /. s0 -> h[[i, 1]];
Res = ComplexExpand[Res /. s -> h[[i, 1]]]; Print[Res],
If[r[[i]] == 2, ResII[s_] = Res2[s] /. s0 -> h[[i, 1]];
ResII[s_] = ComplexExpand[ResII'[s] /. s -> h[[i, 1]]];
Print[ResII[s]],
If[r[[i]] == 3, ResIII[s_] = Res3[s] /. s0 -> h[[i, 1]];
ResIII[s_] = {1/2}*{ComplexExpand[
ResIII''[s] /. s -> h[[i, 1]]]}; Print[ResIII[s]]]]], {i, 1,
j}])
Example.
Natalia[2*s - 1, (s^2 + 1)*(s - 2)^3]
{{{1/2 (-((14 E^(2 t))/125)-4/25 E^(2 t) t+3/5 E^(2 t) t^2)}}}
{{(7 Cos[t])/250+I (-((12 Cos[t])/125)+(7 Sin[t])/250)+(12 Sin[t])/125}}
{{(7 Cos[t])/250+I ((12 Cos[t])/125-(7 Sin[t])/250)+(12 Sin[t])/125}}
There is another option, which we demonstrate on the same example.
P = 2 s - 1 (* Defines polynomial P *)
Out[1]= -1 + 2 s
Q = (s^2 + 1)^2 (s - 2)^3 (* Defines polynomial Q *)
Out[2]= (-2 + s)^3 (1 + s^2)^2
s /. Solve[Q == 0] (* Finds the roots of Q(s)=0 *)
Out[3]= {-I, -I, I, I, 2, 2, 2}
Tally[%] (* Finds the number of repeats of each root (multiplicity)*)
Out[4]= {{-I, 2}, {I, 2}, {2, 3}}
MatrixForm[%] (* Creates solutions matrix with roots in one column and multiplicities in another *)
Out[5]=
(-i 2 )
( i 2 )
( 2 3 )
Dimensions[%] (* Measures the dimensions of the matrix (2x2),(3x2),(6x2), etc*)
Out[6]= {3, 2}
v = Part[%, 1] (* Finds the length of the matrix (v=number of rows) *)
Out[7]= 3
Here we start the Do loop to find residue for each root, where each row of the solutions matrix contains a root and its multiplicity
Do[T := Tally[s /. Solve[Q == 0]];
M := MatrixForm[T]; (* Recreates the solutions matrix for use in Do loop *)
r := Extract[Extract[Extract[M, 1], l], 1]; (* Extracts the root (r) from row of the matrix *)
m := Extract[Extract[Extract[M, 1], l], 2]; (* Extracts multiplicity (m) of root from row of the matrix *)
f = ((((s - r)^m) (E^(s*t)) (P))/Q);
F = Simplify[f]; (* Simplifies f into nicely factored form *)
d = (1/(m - 1)!) D[F, {s, If[m > 1, m - 1, 0]}]; (* it is the equation for residue *)
Res = d /. s -> r; (* Calculates residue at a particular root (r=root) *)
Print[Y = ComplexExpand[Re[Res], {I}]], {l, v}]
It takes the Euler expansion of previous line of code and extracts all
real parts of that expression. Final output will contain several terms,
that are functions of t, that will be the total residue when
added. Note that the Res function computes the residue for each root
by taking roots and multiplicities from row, where l ranges from
1 to v, the length of the solutions matrix.
Out[8]= -((17 Cos[t])/625)-6/125 t Cos[t]+(31 Sin[t])/625+7/500 t Sin[t] -((17 Cos[t])/625)-6/125 t Cos[t]+(31 Sin[t])/625+7/500 t Sin[t] (34 E^(2 t))/625-14/125 E^(2 t) t+3/50 E^(2 t) t^2
To check the answer, we type:
InverseLaplaceTransform[(2 s - 1)/((s^2 + 1)^2 (s - 2)^3), s, t]
Out[9]=
(1/1250)(68 E^(2 t) - 140 E^(2 t) t + 75 E^(2 t) t^2 - 68 Cos[t] -
120 t Cos[t] + 124 Sin[t] + 35 t Sin[t])
I. How to define functions
LaplaceTransform[{y''[t] + 5 y'[t] + 6 y[t] == Sin[2 t], y[0] == -1, y'[0] == 2}, t, lambda]
Out[2]= {6 LaplaceTransform[y[t], t, lambda] +
lambda^2 LaplaceTransform[y[t], t, lambda] +
5 (lambda LaplaceTransform[y[t], t, lambda] - y[0]) - lambda y[0] -
Derivative[1][y][0] == 2/(4 + lambda^2), (y[0] == -1)/lambda, (
Derivative[1][y][0] == 2)/lambda}
LaplaceTransform[y''[t] + 5 y'[t] + 6 y[t] == Sin[2 t], t, lambda];
% /. {y[0] -> -1, y'[0] -> 5}
Out[3]= -5 + lambda + 6 LaplaceTransform[y[t], t, lambda] +
lambda^2 LaplaceTransform[y[t], t, lambda] +
5 (1 + lambda LaplaceTransform[y[t], t, lambda]) == 2/(4 + lambda^2)
Solve[%, LaplaceTransform[y[t], t, lambda]]
Out[4]= {{LaplaceTransform[y[t], t, lambda] -> (
2 - 4 lambda -
lambda^3)/((4 + lambda^2) (6 + 5 lambda + lambda^2))}}
InverseLaplaceTransform[%, lambda, t]
Out[5]= {{y[t] -> -(41/13) E^(-3 t) + (9 E^(-2 t))/4 + 1/52 (-5 Cos[2 t] + Sin[2 t])}}
v[t_] = y[t] /. % ;
Plot[v[t], {t, 0, 9}]
I.Differential Equations with Discontinuous Functions
LaplaceTransform[
y''[t] + 5 y'[t] + 6 y[t] == UnitStep[t - 2 ], t, lambda]
Out[15]= 6 LaplaceTransform[y[t], t, lambda] +
lambda^2 LaplaceTransform[y[t], t, lambda] +
5 (lambda LaplaceTransform[y[t], t, lambda] - y[0]) - lambda y[0] -
Derivative[1][y][0] == E^(-2 lambda)/lambda
% /. {y[0] -> -1, y'[0] -> 5}
Out[16]= -5 + lambda + 6 LaplaceTransform[y[t], t, lambda] +
lambda^2 LaplaceTransform[y[t], t, lambda] +
5 (1 + lambda LaplaceTransform[y[t], t,
lambda]) == E^(-2 lambda)/lambda
Solve[%, LaplaceTransform[y[t], t, lambda]]
Out[17]= {{LaplaceTransform[y[t], t, lambda] -> -((
E^(-2 lambda) (-1 + E^(2 lambda) lambda^2))/(
lambda (6 + 5 lambda + lambda^2)))}}
InverseLaplaceTransform[%, lambda, t]
Out[18]= {{y[t] -> -(1/6)
E^(-3 t) (18 -
12 E^t + (-2 E^6 - E^(3 t) + 3 E^(4 + t)) HeavisideTheta[-2 +
t])}}
Plot[HeavisideTheta[t - 2], {t, 0, 6}] (* plot the unit function with discontinuities *)
L[t_, y_] := y''[t] - 5 y'[t] + 6 y[t] + HeavisideTheta[t - 1]
LaplaceTransform[L[t, y] == DiracDelta[t - 2], t, s]
Out[15]= E^-s/s + 6 LaplaceTransform[y[t], t, s] +
s^2 LaplaceTransform[y[t], t, s] -
5 (s LaplaceTransform[y[t], t, s] - y[0]) - s y[0] -
Derivative[1][y][0] == E^(-2 s)
% /. {y[0] -> -1, y'[0] -> 5}
Out[16]= -5 + E^-s/s + s + 6 LaplaceTransform[y[t], t, s] +
s^2 LaplaceTransform[y[t], t, s] -
5 (1 + s LaplaceTransform[y[t], t, s]) == E^(-2 s)
Solve[%, LaplaceTransform[y[t], t, s]]
Out[17]= {{LaplaceTransform[y[t], t, s] -> -((
E^(-2 s) (E^s - s - 10 E^(2 s) s + E^(2 s) s^2))/(
s (6 - 5 s + s^2)))}}
InverseLaplaceTransform[%, s, t]
Out[18]= {{y[t] -> -(1/(
6 E^6))(-6 E^(6 + 2 t) (-8 + 7 E^t) -
6 E^(2 t) (-E^2 + E^t) HeavisideTheta[-2 + t] +
E^3 (E - E^t)^2 (E + 2 E^t) HeavisideTheta[-1 + t])}}
v[t_] = y[t] /. %
Plot[v[t], {t, 0, 2}]
Clear[x,y,t,z];
soln = DSolve[{x''[t] + 25 x[t] == 0, x[0] == 1, x'[0] == 0}, x[t], t]
Plot[x[t] /. soln, {t, -1, 2.5}]
s[t_] = x[t]/.soln[[1]]
Plot[s[t],{t,0,3},AxesLabel->{"t","Displacement"}]
soln = DSolve[{x''[t] + 17 x'[t] + 16 x[t] == 0, x[0] == 1,
x'[0] == 5}, x[t], t];
s1[t_] = x[t] /. soln[[1]]
Out[32]= 1/5 E^(-16 t) (-2 + 7 E^(15 t))
Plot[s1[t], {t, 0, 3}, AxesLabel -> {"t", "Displacement"}]
>>>> displace1.jpg
When does the maximum excursion occur?
FindRoot[s1'[t] == 0, {t, 0}]
Out[9]= {t -> 0.101322}
What is the maximum excursion?
s1[t /. %]
Out[10]= 1.18603
soln = DSolve[{x''[t] + 2 x'[t] + 37 x[t] == 0, x[0] == -1,
x'[0] == 5}, x[t], t]
Out[2]= -(1/3) E^-t (3 Cos[6 t] - 2 Sin[6 t])}}
s3[t_] = x[t] /. soln[[1]]
Clear[x,t];
soln = DSolve[{x''[t] + 2 x'[t] + 37 x[t] == 0, x[0] == -1,
x'[0] == 5}, x[t], t]
s3[t_] = x[t] /. soln[[1]]
Plot[s3[t], {t, 0, 3}, PlotRange -> {-1, 1}]
Out[19]= {{x[t] -> -(1/3) E^-t (3 Cos[6 t] - 2 Sin[6 t])}}
Out[20]= -(1/3) E^-t (3 Cos[6 t] - 2 Sin[6 t])
Out[21]=
>>>>> solution3.jpg
amplitude =
s3[t] /. c3_ Exp[c4_] (c1_ Cos[a_] + c2_ Sin[a_]) ->
c3*Sqrt[c1^2 + c2^2]
Out[19]= -(Sqrt[13]/3)
Plot[{amplitude*Exp[-t], -amplitude*Exp[-t], s3[t]}, {t, 0, 3},
PlotStyle -> {Blue, Blue, Black}]
>>>>> amplitude.jpg
Forced Oscillations
Martha L. Abell, James P. Braselton
Differential Equations With Mathematica,
Academic Press, 2004
ISBN 0120415623, 978012041562
Alfred Gray, Mike Mezzino, and Mark Pinsky
Introduction to Ordinary Differential Equations with Mathematica: An Integrated Multimedia Approach
Springer
ISBN-10: 0387944818 | ISBN-13: 978-0387944814
Brian R. Hunt, Ronald L. Lipsman, John E. Osborn, Donald A. Outing, Jonathan Rosenberg
Differential Equations with Mathematica, 3rd Edition
ISBN: 978-0-471-77316-0
Clay C. Ross
Differential Equations
An introduction with Mathematica
Springer-Verlag, 1995
ISBN: 0-387-94301-3