0% found this document useful (0 votes)
104 views12 pages

Laplace Matlab Full

1. MATLAB can be used to calculate Laplace transforms and inverse Laplace transforms symbolically. The laplace and ilaplace functions are used. 2. MATLAB can also help with partial fraction expansions, which are useful for inverting transforms with repeated or complex poles. The residue function provides the coefficients in the partial fraction expansion. 3. Examples demonstrate calculating the transforms of simple functions as well as inverting transforms with repeated real poles, using both manual methods and MATLAB functions.

Uploaded by

hashmalshrfy030
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views12 pages

Laplace Matlab Full

1. MATLAB can be used to calculate Laplace transforms and inverse Laplace transforms symbolically. The laplace and ilaplace functions are used. 2. MATLAB can also help with partial fraction expansions, which are useful for inverting transforms with repeated or complex poles. The residue function provides the coefficients in the partial fraction expansion. 3. Examples demonstrate calculating the transforms of simple functions as well as inverting transforms with repeated real poles, using both manual methods and MATLAB functions.

Uploaded by

hashmalshrfy030
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Laplace Transforms with MATLAB

a. Calculate the Laplace Transform using Matlab

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.

here is an example for the function f(t),

f (t ) = −1.25 + 3.5te −2t + 1.25e −2t

>> 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)

which corresponds to F(s),


( s − 5)
F ( s) =
s ( s + 2) 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)

Which corresponds to f(t)

f (t ) = −1.25 + 3.5te −2t + 1.25e −2t


Alternatively one can write
>> ilaplace((s-5)/(s*(s+2)^2))

Here is another example.

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

Which gives f(t),


f (t ) = [4 − 4e −2t cos(t ) + 2e −2t sin(t )]u (t )
making use of the trigonometric relationship,
x sin(α ) + y cos(α ) = R sin(α + β )
and
x cos(α ) − y sin(α ) = R cos(α + β )
with
R = x2 + y2
β = tan −1 ( y / x)

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:

2 heaviside(t-10) exp(-5/2t+25) sinh(1/2t-5)

This can be re-written, using the definition of the sinh(x) function:

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

Therefore, the partial fraction expansion is:

−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.

Example 1 Repeated Real Poles


Find the inverse Laplace transform of
12
V (s) =
s ( s + 8s + 16 )
2

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

A repeated pole of multiplicity m is listed m times corresponding to the m terms


k1 k2 km
, 2
, ..., m
s − p (s − p) (s − p)

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 ⎥

Example 2 Complex Poles


Find the inverse Laplace transform of
12 s + 78
V (s) =
s + 8 s + 52
2

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

Now use the property e − at f ( t ) ↔ F ( s + a ) and the Laplace transform pairs


ω s
sin ωt for t ≥ 0 ↔ and cos ωt for t ≥ 0 ↔
s + ω2
2
s + ω2
2

to find the inverse Laplace transform:


12 s 5 ( 6)
v ( t ) = e − 4t ℒ -1[ + 2 ] = e − 4t [ 12 cos(6t) + 5 sin (6t) ] for t > 0
s +6 s +6
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:

>>num = [12 78];


>>den = [1 8 52];

Now the command

>>[r, p] = residue(num, den)

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 ) ⎤⎦

Thus we have the following 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 )

In the present case a = 6, b = −2.5, c = −4 and d = 6 so we have


v ( t ) = e −4 t ⎡⎣12 cos ( 6 t ) + 5sin ( 6 t ) ⎤⎦ for t > 0

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

Next use phasors to combine the cosine terms


V (ω ) = 12∠0° + 5∠ − 90° = 12 − j 5 = 13∠ − 22.62°

Now v(t) is expressed as v ( t ) = 13 e −4 t cos ( 6 t − 22.62° ) for t > 0

Example 3 Both Real and Complex Poles


Find the inverse Laplace transform of

105 s + 840 105 s + 840


V (s) = = 4
( s + 9.5 s + 17.5)( s + 8 s + 80 ) s + 17.5 s + 173.5 s 2 + 900 s + 1400
2 2 3

Solution
Using MATLAB

>> num=[105 840];


>> den=conv([1 9.5 17.5],[1 8 80]);
>> [r,p] = residue(num, den)
r =
-0.8087 + 0.2415i
-0.8087 - 0.2415i
-0.3196
1.9371
p =
-4.0000 + 8.0000i
-4.0000 - 8.0000i
-7.0000
-2.5000

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 )

with a = −0.8087, b = 0.2415, c = −4 and d = 8 we have


⎡ −0.8087 + j 0.2415 −0.8087 − j 0.2415 ⎤ −4 t
L −1 ⎢ + ⎥ = e ⎡⎣ −1.6174 cos ( 8 t ) + 0.483sin ( 8 t ) ⎤⎦
⎣ s − ( −4 + j 8 ) s − ( −4 − j 8 ) ⎦

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

and v ( t ) = 8.2 e −5.2 t − 3.6 e −4.5t + 7 e −1.25t for t > 0

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

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 )
with a = 3, b = −6, c = −2 and d = 5 we have
v ( t ) = e −2 t ( 6 cos ( 5 t ) + 12sin ( 5 t ) ) + e −4 t ( 2 + 3 t ) for t > 0

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

and v ( t ) = e −4 t (1 − 2 t + 3 t 2 ) for t > 0

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

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 )
with a = 0, b = 4.6154, c = −2.5 and d = 6.5 we have

v ( t ) = −9.2308 e −2.5t sin ( 6.5 t ) for t > 0

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

and v ( t ) = −3 e5t + 3 e −5t for t > 0

You might also like