Laplace Matlab Full
Laplace Matlab Full
Calculating the Laplace F(s) transform of a function f(t) is quite simple in Matlab. First
you need to specify that the variable t and s are symbolic ones. This is done with the
command
>> syms t s
Next you define the function f(t). The actual command to calculate the transform is
>> F=laplace(f,t,s)
To make the expression more readable one can use the commands, simplify and pretty.
>> syms t s
>> f=-1.25+3.5*t*exp(-2*t)+1.25*exp(-2*t);
>> F=laplace(f,t,s)
F =
-5/4/s+7/2/(s+2)^2+5/4/(s+2)
>> simplify(F)
ans =
(s-5)/s/(s+2)^2
>> pretty(ans)
s - 5
----------
2
s (s + 2)
Alternatively, one can write the function f(t) directly as part of the laplace command:
>>F2=laplace(-1.25+3.5*t*exp(-2*t)+1.25*exp(-2*t))
ESE216 1
b. Inverse Laplace Transform
The command one uses now is ilaplace. One also needs to define the symbols t and s.
Lets calculate the inverse of the previous function F(s),
( s − 5)
F ( s) =
s ( s + 2) 2
>> syms t s
>> F=(s-5)/(s*(s+2)^2);
>> ilaplace(F)
ans =
-5/4+(7/2*t+5/4)*exp(-2*t)
>> simplify(ans)
ans =
-5/4+7/2*t*exp(-2*t)+5/4*exp(-2*t)
>> pretty(ans)
- 5/4 + 7/2 t exp(-2 t) + 5/4 exp(-2 t)
10( s + 2)
F (s) =
s ( s 2 + 4s + 5)
>> F=10*(s+2)/(s*(s^2+4*s+5));
>> ilaplace(F)
ans =
-4*exp(-2*t)*cos(t)+2*exp(-2*t)*sin(t)+4
One can also write that f(t) = [4 + 4.47e −2t cos(t − 153.4o )]u (t )
ESE216 2
Matlab often gives the inverse Laplace Transform in terms of sinhx and coshx. Using the
following definition one can rewrite the hyperbolic expression as a function of
exponentials:
ex + e−x
sinh( x) =
2
e − e−x
x
cosh(s ) =
2
Also, you may find the “Heaviside(t) function which corresponds to the unit step function
u(t): thus the function H(t) = heaviside(t) =0 for t<0 and H(t) = heaviside(t)=1 for t>0.
As an example, suppose that Matlab gives you the following result for the inverse
Laplace transform:
2u(t)
e 0.5t −5 − e −2.5t +5
f (t ) = 2u (t − 10).e − 2.5( t −10 ) [ ] = u (t − 10).e −2.5t + 25+0.5t −5 − e −2.5t + 25−0.5t +5
2
= u (t − 10)[e − 2t + 20 −e −3t + 30
]
= [e − 2 ( t −10 ) − e −3( t −10 ) ]u (t − 10)
This last expression is closer to what your hand calculations will give you for the invers
Laplace Transform.
ESE216 3
Using MATLAB for Laplace Transforms
Examples:
1. You can compute Laplace transform using the symbolic toolbox of MATLAB. If you
want to compute the Laplace transform of x(t ) = t , you can use the following MATLAB
program.
>> f=t;
>> syms f t
>> f=t;
>> laplace(f)
ans =1/s^2
where f and t are the symbolic variables, f the function, t the time variable.
2. The inverse transform can also be computed using MATLAB. If you want to compute
24
the inverse Laplace transform of F ( s ) = , you can use the following command
s ( s + 8)
lines.
>> syms F S
>> F=24/(s*(s+8));
>> ilaplace(F)
ans =
3-3*exp(-8*t)
3. We can also do inverse Laplace transform using partial fraction expansion, and
MATLAB can help you with that. If you want to find the partial-fraction expansion of
4s 2 + 4s + 4
Y (s) = 2 2 , the following MATLAB program gives you the coefficients in
s ( s + 3s + 2)
the expansion. You write the coefficients of the numerator and the denominator in
separate vectors and MATLAB gives you the coefficients with the corresponding poles in
the expansion.
>> n=[0 0 4 4 4];
>> d=[1 3 2 0 0];
>> [r,p,k]=residue(n,d)
r=
-3
4
-1
2
p=
-2
-1
0
0
−3 4 1 2
+ − + 2
s + 2 s +1 s s
The following examples illustrate the use of MATLAB for finding the inverse Laplace transform
of functions having complex or repeated poles.
Solution
2
First, we will do this problem without using MATLAB. Noticing that s 2 + 8s + 16 = ( s + 4) ,
we begin the partial fraction expansion:
3
12 12 k −3
V (s) = = = + +4
s ( s + 8s + 16) s ( s + 4)
2
2
s + 4 ( s + 4)2 s
2
Next, the constant k is evaluated by multiplying both sides of the last equation by s ( s + 4) .
3 ⎛3 ⎞ 3
12 = ks ( s + 4) − 3s + ( s + 4) = ⎜⎜ + k ⎟⎟⎟ s 2 + (3 + 4k ) s + 12 ⇒ k = −
2
4 ⎜
⎝4 ⎠ 4
⎡ 3 3⎤
⎢− ⎥ ⎛
Finally v (t ) = L ⎢−1 ⎢ 4 +
−3
+ 4 ⎥ = ⎜ 3 − e−4 t ⎛⎜ 3 + 3 t ⎞⎟⎞⎟⎟ u (t ) V
⎥ ⎜ ⎜⎝⎜ 4 ⎟
⎢ s + 4 ( s + 4)
2
s ⎥ ⎜⎝ 4 ⎠⎟⎟⎠
⎢⎣ ⎥⎦
Next, we perform the partial fraction expansion using the MATLAB function residue:
>>num = [12];
>>den = [1 8 16 0];
>>[r, p] = residue(num, den)
MATLAB responds
r =
-0.7500
-3.0000
0.7500
p =
-4
-4
0
1
listed in order of increasing powers of s – p. The constants k1, k2,…,km are the corresponding
residues, again listed in order of increasing powers of s – p. In our present case, the pole p = −4
has multiplicity 2 and the first two terms of the partial fraction expansion are
−0.75 −3 −0.75 −3
+ = +
s − (−4) ( s − (−4))2
s + 4 ( s + 4)2
The entire partial fraction expansion is
−0.75 −3 0.75 −0.75 −3 0.75
+ + = + +
s − (−4) ( s − (−4))2
s − ( 0) s + 4 ( s + 4)2
s
Finally, as before
⎡ −0.75 −3 0.75 ⎤⎥
v (t ) = L −1 ⎢ = (0.75 − e−4 t (0.75 + 3 t )) u (t ) V
⎢ s+4 + 2
+ ⎥
⎢⎣ ( s + 4) s ⎥
⎦
Solution
First, we will do this problem without using MATLAB. Notice that the denominator does not
factor any further in the real numbers. Let’s complete the square in the denominator
12 s + 78 12 s + 78 12 s + 78 12 ( s + 4 ) + 30 12 ( s + 4 ) 5 ( 6)
V (s) = = 2 = = = +
s + 8 s + 52 ( s + 8 s + 16 ) + 36 ( s + 4 ) + 36 ( s + 4 ) + 36 ( s + 4 ) + 62 ( s + 4 )2 + 62
2 2 2 2
Next, we will use MATLAB to do the partial fraction expansion. First, enter the numerator and
denominator polynomials as vectors listing the coefficients in order of decreasing power of s:
2
tells MATLAB to do the partial fraction expansion return p, is a list of the poles of of V(s), and
r, a list of the corresponding residues. In the present case MATLAB returns
r =
6.0000 - 2.5000i
6.0000 + 2.5000i
p =
-4.0000 + 6.0000i
-4.0000 - 6.0000i
6 − j 2.5 6 + j 2.5
indicating V (s) = +
s − ( −4 + j 6 ) s − ( −4 − j 6 )
Notice that the first residue corresponds to the first pole and the second residue corresponds to
the second pole. (Also, we expect complex poles to occur in pairs of complex conjugates and for
the residues corresponding to complex conjugate poles to themselves be complex conjugates.)
Taking the inverse Laplace transform, we get
v ( t ) = ( 6 − j 2.5 ) e (
− −4 + j 6 ) t
+ ( 6 + j 2.5 ) e (
− −4− j 6 ) t
This expression, containing as it does complex numbers, isn’t very convenient. Fortunately, we
can use Euler’s identity to obtain an equivalent expression that does not contain complex
numbers. Since complex poles occur quite frequently, its worthwhile to consider the general
case:
a + jb a − jb
V (s) = +
s − (c + j d ) s − (c − j d )
The inverse Laplace transform is
v ( t ) = ( a + j b ) e(
c+ j d )t
+ ( a − j b ) e(
c− j d )t
⎡ ⎛ e j d t + e− j d t ⎞ ⎛ e j d t − e− j d t ⎞ ⎤
= ect ⎡⎣( a + j b ) e j d t + ( a − j b ) e− j d t ⎤⎦ = ect ⎢ 2 a ⎜ ⎟ − 2 b ⎜ ⎟⎥
⎣ ⎝ 2 ⎠ ⎝ 2j ⎠⎦
− jdt − jdt
e +e
jdt
e −e
jdt
Euler identity says = cos ( d t ) and = sin ( d t )
2 2j
Consequently v ( t ) = ect ⎡⎣ 2 a cos ( d t ) − 2b sin ( d t ) ⎤⎦
It’s sometimes convenient to express this answer in a different form. First, express the sine term
as an equivalent cosine
3
v ( t ) = e −4t ⎡⎣12 cos ( 6 t ) + 5cos ( 6 t − 90° ) ⎤⎦ for t > 0
Solution
Using MATLAB
Consequently
−0.8087 + j 0.2415 −0.8087 − j 0.2415 −0.3196 1.9371
V (s) = + + +
s − (−4 + j 8) s − (−4 − j 8) s − (−7) s − (−2.5)
Using the Laplace transform pair
a + jb a− jb
ect ⎡⎣ 2 a cos ( d t ) − 2b sin ( d t ) ⎤⎦ ↔ +
s − (c + j d ) s − (c − j d )
Taking the inverse Laplace transform of the remaining terms of V(s) we get
4
v ( t ) = e −4 t ⎡⎣ −1.6174 cos ( 8 t ) + 0.483sin ( 8 t ) ⎤⎦ − 0.3196 e −7 t + 1.9371 e−2.5t for t > 0
Problem 1
11.6 s 2 + 91.83 s + 186.525
Find the inverse Laplace transform of V ( s ) = 3
s + 10.95 s 2 + 35.525 s + 29.25
Solution 1
Using MATLAB:
>> num = [11.6 91.83 186.525];
>> den = [1 10.95 35.525 29.25];
>> [r,p]=residue(num,den)
r =
8.2000
-3.6000
7.0000
p =
-5.2000
-4.5000
-1.2500
Consequently
8.2 −3.6 7 8.2 −3.6 7
V (s) = + + = + +
s − ( −5.2 ) s − ( −4.5 ) s − ( −1.25 ) s + 5.2 s + 4.5 s + 1.25
Problem 2
8 s 3 + 139 s 2 + 774 s + 1471
Find the inverse Laplace transform of V ( s ) =
s 4 + 12 s 3 + 77 s 2 + 296 s + 464
Solution 2
Using MATLAB:
>> num = [8 139 774 1471];
>> den = [1 12 77 296 464];
>> [r,p]=residue(num,den)
r =
3.0000 - 6.0000i
3.0000 + 6.0000i
2.0000
3.0000
p =
-2.0000 + 5.0000i
-2.0000 - 5.0000i
-4.0000
-4.0000
5
3− j6 3+ j 6 2 3
Consequently V (s) = + + +
s − ( −2 + j 5 ) s − ( −2 − j 5 ) s − ( −4 ) ( s − ( −4 ) )2
Problem 3
s 2 + 6 s + 11 s 2 + 6 s + 11
Find the inverse Laplace transform of V ( s ) = =
s 3 + 12 s 2 + 48 s + 64 ( s + 4)
3
Solution 3
Using MATLAB:
>> num = [1 6 11];
>> den = [1 12 48 64];
>> [r,p]=residue(num,den)
r =
1.0000
-2.0000
3.0000
p =
-4.0000
-4.0000
-4.0000
1 −2 3
Consequently V (s) = + +
s − ( −4 ) ( s − ( −4 ) ) ( s − ( −4 ) )3
2
Problem 4
−60
Find the inverse Laplace transform of V ( s ) =
s + 5 s + 48.5
2
Solution 4
The denominator does not factor any further in the real numbers. Let’s complete the square in the
denominator
−60 −60 −60 −9.23 ( 6.5 )
V (s) = 2 = = =
s + 5 s + 48.5 ( s + 2.5 ) + 42.25 ( s + 2.5 ) + 6.5 2 ( s + 2.5 )2 + 6.5 2
2 2
6
ω
Now use e − at f ( t ) ↔ F ( s + a ) and sin ωt for t > 0 ↔ to find the inverse Laplace
s + ω2
2
transform
−9.23 ( 6.5 )
v ( t ) = e − 2.5t ℒ-1[ ] = −9.23 e − 2.5t sin (6.5 t) for t > 0
( s + 2.5)
2
+ 6.5 2
Using MATLAB:
>> num = [-60];
>> den = [1 5 48.5];
>> [r,p]=residue(num,den)
r =
0 + 4.6154i
0 - 4.6154i
p =
-2.5000 + 6.5000i
-2.5000 - 6.5000i
Problem 5
−30
Find the inverse Laplace transform of V ( s ) =
s − 25
2
Solution 5
Using MATLAB:
>> num = [-30];
>> den = [1 -25];
>> [r,p]=residue(num,den)
r =
-3
3
p =
5
-5
−3 3 −3 3
Consequently V (s) = + = +
s − 5 s − ( −5 ) s − 5 s + 5