You are on page 1of 5

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

1. syms t s
2. f=-1.25+3.5*t*exp(-2*t)+1.25*exp(-2*t);
3. F=laplace(f,t,s)
4. simplify(F)
5. pretty(ans)

>> ML5

s - 5
----------
2
s (s + 2)

which corresponds to F(s),

F ( s)
s 5
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))
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),

F ( s)
s 5
s ( s 2) 2

1. syms t s
2. F=(s-5)/(s*(s+2)^2);
3. ilaplace(F)
4. simplify(ans)
5. pretty(ans)

>> MlapDsolve41

ans =

(5*exp(-2*t))/4 + (7*t*exp(-2*t))/2 - 5/4

5 exp(-2 t) 7 t exp(-2 t)
----------- + ------------- - 5/4
4 2

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.

10s 2
F (s)
s( s 2 4s 5)

1.syms t s
2.F=10*(s+2)/(s*(s^2+4*s+5));
3.ilaplace(F)
4.simplify(ans)
5.pretty(ans)
>> MlapDsolve41
ans =

4 - 4*exp(-2*t)*(cos(t) - sin(t)/2)

/ sin(t) \
4 - 4 exp(-2 t) | cos(t) - ------ |
\ 2 /

c. Solving 2nd Order Differential Equations by Using Laplace Transform

Example 16:
A first order differential equation involving current I in a series R-L circuit is given by:

+ 5 = 20 3 and = 0 at time = 0.


{} + 5{} = {20 3 }
20
[{} (0)] + 5{} =
+3
20
[ + 5]{} =
+3
20
{} = (+3)(+5)
20
() = 1 {(+3)(+5) }
10 10
() = 1 {+3 } 1 {+5 } (by using partial fraction)
Taking the inverse Laplace transform, we obtain
() = 10 3 10 5

syms t s
F=(20)/((s+3)*(s+5));
ilaplace(F)
pretty(ans)

>> MatlabD1
ans =
10*exp(-3*t) - 10*exp(-5*t)

Example 17:
Solve " + 4 = 0; (0) = 2, (0) = 2.
{ } + 4{} = {0}
[ 2 () (0) (0)] + 4() = 0
[ 2 + 4]() . 2 2 = 0
[ 2 + 4]() = 2 + 2
2+2 2 2
() = 2 +4 = 2 +4 + 2 +4
Taking the inverse Laplace transform, we obtain
1
() = 1 {()} = 2 1 {2 +22 } + 2 1 {2 +22 }
= sin 2 + 2 cos 2

syms t s
F=(2+2*s)/(s^2+4);
ilaplace(F)
pretty(ans)

>> MlapD2
ans =
2*cos(2*t) + sin(2*t)
2 cos(2 t) + sin(2 t)

Example 18:
Solve the following 2nd order DE:
" 10 + 9 = 5; (0) = 1, (0) = 2
{ } 10{ } + 9{} = {5}
5
[ 2 () (0) (0)] 10[() (0)] + 9() = 2

[ 2 10 + 9]() + [ + 10](0) (0) = 0
5
[ 2 10 + 9]() + 10 2 = 2

5
[ 2 10 + 9]() = + 12
2
5
+12
2
() = 2 10+9
53 +122
() = 2 (9)(1)
The partial fraction decomposition for this transform is

() = + 2 + 9 + 1

50 5 31
2
() = 81 + 92 + 9
81
1

Taking the inverse transform give us the solution to this 2nd order DE:
50 5 31
() = 1 {()} = 81 + 9 + 81 9 2

syms t s
F=(5/s^2-s+12)/(s^2-10*s+9);
ilaplace(F)
pretty(ans)

MlapD3
ans =
(5*t)/9 + (31*exp(9*t))/81 - 2*exp(t) + 50/81
5 t 31 exp(9 t)
--- + ----------- - 2 exp(t) + 50/81
9 81

You might also like