Вы находитесь на странице: 1из 95

• Prof Dr.

NASSERELDEEN AHMED KABBASHI

• DEPARTMENT OF BIOTECHNOLOGY ENGINEERING


• nasreldin@iium.edu.my, Tel : Ext. 4524
• ODE MATLAB
BTEN 4321 & 4416
Bioprocess Control & Instrumentation
MATLAB 3
DIFFERENTIAL EQUATION &
LAPLACE TRANSFORMATION
with MATLAB

3
Differential Equations with MATLAB

MATLAB has some powerful features for


solving differential equations of all types.
We will explore some of these features for
the Constant Coefficient Linear Ordinary
Differential Equation forms.
The approach here will be that of the
Symbolic Math Toolbox. The result will be
the form of the function and it may be
readily plotted with MATLAB.
4
Symbolic Differential Equation Terms

y y

dy Dy
dt
2
d y
2 D2y
dt
n
d y
n Dny
dt
5
Finding Solutions to Differential Equations

 Solving a First Order Differential Equation


Solving a Second Order Differential Equation
Solving Simultaneous Differential Equations
Solving Nonlinear Differential Equations
Numerical Solution of a Differential Equation

6
Approach to Solving
Initial Value Problems
• Given an nth order time domain differential equation of x(t)
with initial initial conditions for x(t) and its n-1
derivatives
1. Take the Laplace Transform of the differential equation to
get a function of X(s)
2. Substitute Initial Conditions
3. Write equation for desired function
4. Convert X(s) to be strictly rational and use Partial Fraction
Expansion
5. Use the table method to get the Inverse Laplace Transform
thus getting x(t) 7
2nd Order DE Example

• Find the solution, y(t), for the differential equation:

•• • •
y (t ) + 6 y (t ) + 8 y (t ) = x (t ) + x (t )
 Subject to the Conditions:


y (0) = 3 y(0) = 1 x(t ) = u (t )

8
Left Side Laplace Transform

• Using the following transformations:


•  ••  2 •
LT  x(t ) = sX ( s) − x(0), LT  x (t ) = s X ( s ) − sx(0) − x(t )
   
 Take the Laplace Transform of the Left Side of the original equation

•• •
y (t ) + 6 y (t ) + 8 y (t )
⇓ LT ⇓ LT ⇓ LT

s Y ( s) − sy (0) − y (0) + 6{sY ( s) − y (0)} + 8Y ( s)
2
9
Right Side Laplace Transform

 Take the General Laplace Transform of the •


Right Side of the original equation
x(t ) + x(t )
⇓ LT ⇓ LT

sX ( s) − x(0 ) + X ( s)

• Given x(t) is the discontinuous Unit Step function


• Initial Condition of x(t) is considered x(0-) = 0
• Minus subscript indicates the value of x(t) when
approaching from the left (negative time)
10
Laplace Transform
with Initial Conditions
• The transformed equation is then:

s 2Y ( s) − sy (0) − • (0) + 6{sY ( s) − y (0)} + 8Y ( s) =


 y 
 
{ }
sX ( s) − x(0 − ) + X ( s)

y (0) = 3 y ( 0) = 1 x (0 − ) = 0
 Substituting in the initial conditions it becomes:

[s Y (s) − s − 3]+ 6[sY (s) − 1] + 8Y (s) = [sX (s) − 0] + X (s)


2
11
Substitute and Simplify
• x(t) was given as the
X ( s) = LT {u (t )} =
1
unit step function u(t)
whose transform is: s
[s Y (s) − s − 3]+ 6[sY (s) − 1] + 8Y (s) = [sX (s) − 0] + X (s)
2

[s Y (s) − s − 3]+ 6[sY (s) − 1] + 8Y (s) = s s  − 0 + s


2  1  1
  

[ ]
 Simplifying terms yields:
1
Y ( s) s + 6s + 8 − s − 9 = 1 +
2

12
s
Equation for Y(s)

• Reorder terms to create an equation for Y(s)

[ ]
Y ( s) s + 6s + 8 − s − 9 = 1 +
2 1
s

1 1
1+ + s + 9 + s + 10
s s s + 10s + 1
2
Y (s) = 2 = =
s + 6s + 8 (s + 2)(s + 4) s(s + 2)(s + 4)
13
Partial Fraction Expansion
• Perform partial fraction expansion to break into terms with
known Inverse Laplace Transforms

s 2 + 10s + 1 A = sY ( s) s =0 =
1
Y (s) = 8
s( s + 2)( s + 4) 15
B = ( s + 2)Y ( s) s =−2 =
A B C 4
= + + 23
s s+2 s+4 C = ( s + 4)Y ( s) s =−4 = −
8
1 15 23
Y (s) = 8 + 4 + 8
s s+2 s+4 14
Inverse Laplace
 y(t) is the inverse Laplace Transform of Y(s):

1 15 23
Y (s) = 8 − 4 − 8
s s+2 s+4
LT-1

 1 15 − 2t 23 − 4t 
y (t ) =  + e − e u (t )
8 4 8 
15
Exponential DE Example
• Find the solution to the following second order differential
equation with a causal exponential term:

•• •
−t
y (t ) − 3 y (t ) + 2 y (t ) = 2e u (t )
 Subject to the initial conditions:


y (0) = 2 y ( 0) = 1
16
Take Laplace Transform

• Using the transform pairs:


•  ••  2 •
LT  x(t ) = sX ( s ) − x(0), LT  x (t ) = s X ( s ) − sx(0) − x(t )
   
 Take the Laplace Transform of both sides

•• •
y (t ) − 3 y (t ) + 2 y (t ) = 2e −t u (t )
⇓ LT ⇓ LT ⇓ LT ⇓ LT
 2 •

s Y ( s) − sy (0) − y (0) − 3{sY ( s ) − y (0)}
2
+ 2Y ( s ) =
  ( s + 1)
17
Equation for Y(s)

• Replace initial conditions


 2 •

s Y ( s) − sy (0) − y (0) − 3{sY ( s ) − y (0)} + 2Y ( s ) =
2
  ( s + 1)

y (0) = 2 y (0) = 1
2
s Y ( s ) − 2s − 1 − 3sY ( s ) + 6 + 2Y ( s ) =
2

( s + 1)
 Write an equation for Y(s)

 2  1 2 + 2 s 2 + 2 s − 5s − 5
Y (s) =  + 2s − 5 2 =
 ( s + 1)  ( s − 3 s + 2 ) ( s + 1)( s 2
− 3s + 2)
18
Partial Fraction Expansion

• Use Matlab to find imaginary 2s − 0.2


X (s) = 2
poles as symbolic variables s + 1.4s + 1
» poles = roots([1 1.4 1])
poles =
-0.7000 + 0.7141i 7 51
-0.7000 - 0.7141i p1 = − + i
» p1=poly2sym(poles(1),'s'); 10 10
» pretty(p1)
1/2
-7/10 + 1/10 i 51
» p2=poly2sym(poles(2),'s'); 7 51
» pretty(p2) p2 = − − i
1/2 10 10
-7/10 - 1/10 i 51 19
Matlab Verification

 2 s − 0.2 
Use Matlab to verify the entire Inverse Laplace process
−1
x(t ) = LT  2 
 s + 1 .4 s + 1 
» syms x s t
» X=(2*s-0.2)/(s^2+1.4*s+1);
» x=ilaplace(X); pretty(x)
16 1/2 1/2
- -- exp(- 7/10 t) 51 sin(1/10 51 t)
51
1/2
+ 2 exp(- 7/10 t) cos(1/10 51 t)


  51  16 51  51  
x(t ) = e − 0.7 t

2 cos 
t − 
sin  
t u (t )

  10  51  10 20
Inverse Laplace of X2(s)
 Use Matlab to determine Inverse Laplace of X2(s) 1
X 2 (s) = 2
s( s + 1.4s + 1)

» syms s
» X2=1/(s*(s^2+1.4*s+1));
» x2=ilaplace(X2)
x2 =
1-exp(-7/10*t)*cos(1/10*51^(1/2)*t-7/51*
exp(-7/10*t)*51^(1/2)*sin(1/10*51^(1/2)*t)

  51  7 51  51 
cos t  + sin  t u (t )
− 0.7 t
x2 (t ) = 1 − e
  10  15  10 
21
Solving a 1st Order DE

 The Matlab command used to solve differential


equations is dsolve .

dy
 Consider the differential equation: + 2 y = 12
dt

 The general solution is given by:

 Verify the solution using dsolve command


22
Solving a Differential
Equation in Matlab

» syms y t

» ys=dsolve('Dy+2*y=12')

ys =6+exp(-2*t)*C1

 C1 is a constant which is specified by way of the


initial condition

 Dy means dy/dt and D2y means d2y/dt2 etc

23
Verify Results

 Verify results given y(0) = 9

y (0) = 9 → C1 = 3

» ys=dsolve('Dy+2*y=12','y(0)=9')

ys =
6+3*exp(-2*t)

24
Solving a 2nd Order DE

Find the general solution of: d2y 2



2
+c y =0
dt

» syms c y
» ys=dsolve('D2y = - c^2*y')

ys = C1*sin(c*t)+C2*cos (c*t)

y (t ) = C1 sin(ct ) + C2 cos(ct )
25
Solving Simultaneous
Differential Equations Example
 Syntax for solving simultaneous differential equations is:
dsolve('equ1', 'equ2',…)

 Solve the following set of differential equations:

dx dy
= 3x + 4 y = −4 x + 3 y
dt dt
26
General Solution

 Given the equations:

dx dy
= 3x + 4 y = −4 x + 3 y
dt dt

 The general solution is given by:

x(t ) = c1e3t cos(4t ) + c2 e3t sin( 4t )


y (t ) = −c1e sin( 4t ) + c2 e cos(4t )
3t 3t

27
Matlab Verification
 Given the dx dy
equations: = 3x + 4 y = −4 x + 3 y
dt dt

 General x(t ) = c1e3t cos(4t ) + c2 e3t sin( 4t )


solution is:
y (t ) = −c1e sin( 4t ) + c2 e cos(4t )
3t 3t

» syms x y t
» [x,y]=dsolve('Dx=3*x+4*y','Dy=-4*x+3*y')
x = exp(3*t)*(cos(4*t)*C1+sin(4*t)*C2)
y = -exp(3*t)*(sin(4*t)*C1-cos(4*t)*C2)

28
Initial Conditions

 Solve the previous system with the initial conditions:

x(0) = 0 y (0) = 1

» [x,y]=dsolve('Dx=3*x+4*y','Dy=-4*x+3*y',
'y(0)=1','x(0)=0')

x = exp(3*t)*sin(4*t) x = e sin( 4t )
3t

y = exp(3*t)*cos(4*t) y = e 3t cos(4t )

29
Non-Linear Differential Equation Example

dy
 Solve the differential equation: = 4− y 2

dt
Subject to initial condition:
y (0) = 1

» syms y t
» y=dsolve('Dy=4-y^2','y(0)=1')
» y=simplify(y)
y=
y (t ) =
(
2 3e 4t − 1)
2*(3*exp(4*t)-1)/(1+3*exp(4*t))
1 + 3e 4t
30
Specifying the Independent Parameter of a
Differential Equation
 If another independent variable, other than t, is used, it must
be introduced in the dsolve command

dy
 Solve the differential equation: + 2 y = 12
dx
» y=dsolve('Dy+2*y=12','x')

−2 x
y = 6+exp(-2*x)*C1 y ( x) = 6 + C1e

31
Numerical Solution Example
 Not all non-linear differential equations have a closed
form solution, but a numerical solution can be found
2
d y
 Solve the differential equation:
2
+ 9 sin( y ) = 0
dt

y ( 0) = 1
 Subject to initial conditions:

y ( 0) = 0

32
Rewrite Differential Equation
2
d y d 2 y ••
2
+ 9 sin( y ) = 0 2
= y = −9 sin( y )
dt dt
 Rewrite in the
x1 = y • •
following form x2 = y = x1
• ••
x1 (0) = y (0) = 1
x2 = y = −9 sin( y )
• •

x2 = −9 sin( x1 ) x2 (0) = y (0) = 0


33
Solve DE with MATLAB.
2
d y dy
2
+ 3 + 2y = 24
dt dt
y (0) = 10 y '(0) = 0

>> y = dsolve ('D2y + 3*Dy + 2*y = 24',


'y(0)=10', 'Dy(0)=0')
y = 12+2*exp(-2*t)-4*exp(-t)
>> ezplot(y, [0 6])

34
35
Definition of Laplace Transformation:

Let f(t) be a given function defined for all t ≥ 0 ,


then the Laplace Transformation of f(t)
is defined as

Here,
L = Laplace Transform Operator.
f(t) =determining function, depends on t
.
F(s)= Generating function, depends on s
.
36
The Laplace Transformation

Time Domain Frequency Domain


Laplace Transform

Differential Algebraic
equations equations

Input Input
excitation e(t) excitation E(s)
Output Output
response r(t) response R(s)

Inverse Laplace Transform

37
Laplace Transforms with 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

The actual command to calculate the transform is


>> F = Laplace (f , t , s)

38
example for the function f(t)

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

39
Inverse Laplace Transform

The command one uses now is ilaplace .

>> 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)
40
Part 3: Direct Solution
• x(t) for f(t)=u(t) can also be solved
2s − 0.2 + 1
directly in Matlab to yield the same X ( s) = s
results s 2 + 1.4s + 1
» syms s
» X=(2*s-0.2+1/s)/(s^2+1.4*s+1);
» x=ilaplace(X)
x =
1+exp(-7/10*t)*cos(1/10*51^(1/2)*t)
-23/51*exp(-7/10*t)*51^(1/2)*sin(1/10*51^(1/2)*t)

− 0.7 t   51  23 51  51 
x(t ) = 1 + e cos t− sin  t u (t )
  10  51  10 
41
Summary

• Laplace Transform is a useful technique for solving


linear constant coefficient differential equations with
known initial conditions
 Laplace Transform converts time-domain differentiation to multiplication by s terms in the s-domain

 Equations with real poles can be solved efficiently by hand or using Matlab to verify portions

 Matlab is useful for solving complex pole problems, but the solution may not be intuitively
interpreted

42
Reference

• http://www.mathworks.in/help/symbolic/simplify.html

• https://www.google.co.in/#q=laplace+transform+using+matlab

43
Thank You 

44
Chapter Objectives
• Understanding how the Runge-Kutta Fehlberg
methods use RK methods of different orders to
provide error estimates that are used to adjust step
size.
• Familiarizing yourself with the built-in MATLAB
function for solving ODEs.
• Learning how to adjust options for MATLAB’s ODE
solvers.
• Learning how to pass parameters to MATLAB’s
ODE solvers.
• Understanding what is meant by stiffness and its
implications for solving ODEs.
Solution of Differential Equations with
MATLAB
•MATLAB has some powerful features for
solving differential equations of all types. We will
explore some of these features for the CCLODE
forms.
•The approach here will be that of the Symbolic
Math Toolbox.
•The result will be the form of the function and it
may be readily plotted with MATLAB.
Symbolic Differential Equation Terms

y •y

dy •Dy
dt
2
d y
2
•D2y
dt
n
d y
n •Dny
dt
Adaptive Runge-Kutta Methods

• The solutions to some ODE


problems exhibit multiple time
scales - for some parts of the
solution the variable changes
slowly, while for others there are
abrupt changes.
• Constant step-size algorithms
would have to apply a small step-
size to the entire computation,
wasting many more calculations
on regions of gradual change.
• Adaptive algorithms, on the other
hand, can change step-size
depending on the region.
Matlab’s ODE Solvers

• MATLAB ODE solvers


ode23 2nd/3rd Runge-Kutta
ode45 4/5th Runge-Kutta
Integration by ode23 and ode45:
Matlab Command
[t, x] = ode45(‘xprime’, [t0,tf], x0)
where
xprime is a string variable containing the name of the
m-file for the derivatives.
t0 is the initial time
tf is the final time
x0 is the initial condition vector for the state variables
t a (column) vector of time
x an array of state variables as a function of time
ODE Solvers

• LMS and RK solvers are general algorithms that can work with any ODE
• Need a way to pass the function f to the solver

N0 t0 T N t

Solver f

N1, N2,…,NT dN/dt


Using ode Functions
• The functions are generally called in the same way; ode45 is used
as an example:
[t, y] = ode45(odefun, tspan, y0)
– y: solution array, where each column represents one of the
variables and each row corresponds to a time in the t vector
– odefun: function returning a column vector of the right-hand-
sides of the ODEs
– tspan: time over which to solve the system
• If tspan has two entries, the results are reported for those
times as well as several intermediate times based on the
steps taken by the algorithm
• If tspan has more than two entries, the results are reported
only for those specific times
– y0: vector of initial values
ODE function

Defining an ODE function in an M-file

53
... Solving first-order ODEs

Example

54
Output

55
Example
• Another example to solve a 2nd order ODE, y'' + y' + y + t =
0, the matlab code yprime1.m should be like,
• function yp=yprime1(y,t)
• yp(1) = y(2);
• yp(2) = -y(2) - y(1) -t;
• Solve it by
– tspan=[0,10];
– y0 = 0;
– [t,y] = ode23(@yprime1,tspan,y0)
• Plot the graph t vs the first and second column of y to show
the solution y and y’
– plot(t,y(*,1),y(*,2))
Purpose of function files

function output=function_name (input1, input2)

As indicated above, the function file generates the value of outputs every
time it called upon with certain sets of inputs of dependent and independent
variables
function dy=pbr (w, y)

For instance the pbr.m file generates the value of output (dy), every iteration
it is called upon with inputs of independent variable catalyst weight (w) and
dependent variables (y)

NOTE: For pbr.m file, the output dy is actually dX/dW and dP/dW;
The function pbr returns the numerical values of dy or
OUTPUTS for corresponding sets of INPUTS y defined
at given value of y

function dy=pbr(W,y)
global dtube
% operating conditions
To=300+273; %Inlet temperature
Po=1.5*101.325; %Inlet pressure in kPa

In our case,
OUTPUTS (dy) INPUTS
d(P)/dW y(2,:) = P
d(X)/dW y(1,:) = X
Function file name

Function name should match file name

function dy=pbr(W,y)
global dtube
% operating conditions
To=300+273; %Inlet temperature
Po=1.5*101.325; %Inlet pressure in kPa
Semi-colon suppresses the SCREEN
PRINTING of the statement
“To=300+273”

function dy=pbr(W,y)
global dtube
%operating conditions
To=300+273; %Inlet temperature
Po=1.5*101.325; %Inlet pressure in kPa
%defined variables

P=y(1,:);
X=y(2,:);

For convenience sake, I have defined the


variable y(1,:) as Pn and variable y(2,:) as X
%defined variables

P=y(1,:);
X=y(2,:);

COLON indicates that the y is a variable.

That is y(1,:) varies with time


% momentum balance equation or pressure drop equation
dy(1,:)=-(lamda/dw_to_dz_conv)*(1/gasden);

% mole balance equation in terms of conversion changing with catalyst


% weight or dX/dw
dy(2,:)=(kf*pCH3OH)/Fao;

These set of equations calculate the values of the OUPUTS dy

based on previously defined/known constants and/or INPUTS


RUN FILE
This file contains executable commands only

global dtube
dtube = 4e-4; %microreactor diameter 400 micron
Po=1.5*101325;
y0 = [Po 0]; %initial condition for P and X.

W0=0;
Wmax=3.1416*(dt/2)^2*(5e-2)*(1-0.3)*1400;% w=pi*r^2*L*(1-
porosity)*cat_density
Wspan=[W0 Wmax];% Defines integration range

[W,y]=ode15s('pbr', Wspan, y0, []);

hold on

plot(W,y(:,1)/Po,'b-.', W,y(:,2),'r-')
This statement defines the initial condition of the dependent variable

global dtube
dtube = 4e-4; %microreactor diameter 400 micron
Po=1.5*101325;
y0 = [Po 0]; %initial condition for P and X.

W0=0;
Wmax=3.1416*(dt/2)^2*(5e-2)*(1-0.3)*1400;% w=pi*r^2*L*(1-
porosity)*cat_density
Wspan=[W0 Wmax];% Defines integration range

[W,y]=ode15s('pbr', Wspan, y0, []);

hold on

plot(W,y(:,1)/Po,'b-.', W,y(:,2),'r-')
This statement defines the Limits of Integration over which
the Differential Equation must be INTEGRATED over.

global dtube
dtube = 4e-4; %microreactor diameter 400 micron
Po=1.5*101325;
y0 = [Po 0]; %initial condition for P and X.

W0=0;
Wmax=3.1416*(dt/2)^2*(5e-2)*(1-0.3)*1400;% w=pi*r^2*L*(1-
porosity)*cat_density
Wspan=[W0 Wmax];% Defines integration range

[W,y]=ode15s('pbr', Wspan, y0, []);

hold on

plot(W,y(:,1)/Po,'b-.', W,y(:,2),'r-')
This is the Main COMMAND.
An output in form of a matrix of W and y’s will be generated
by solving the differential equations defined/calculated by “pbr”

The ODE solver “ode15s” is used to integrate the differential


equations over the integration limit defined in Wspan as W=W0
to W=Wmax given initial conditions for y’s as y0

W0=0;
Wmax=3.1416*(dtube/2)^2*(5e-2)*(1-0.3)*1400;% w=pi*r^2*L*(1-
porosity)*cat_density
Wspan=[W0 Wmax];% Defines integration range

[W,y]=ode15s('pbr', Wspan, y0, []);

hold on

plot(W,y(:,1)/Po,'b-.', W,y(:,2),'r-')
Another useful command is

wk1write(’filename', [t, y])

This command will write the output [t, y]


that is, all y’s as a function of t

obtained from the ODE solver in a file called “filename”


Solving ordinary differential
equations
• To solve y’ - y – t = 0, the matlab code yprime.m should be like,
function yp = yprime(y,t)
yp = y + t;
• Solve it by
– tspan=[0,10];
– y0 = 0;
– [t,y] = ode23(@yprime,tspan,y0)
• Plot the graph t vs y to show the solution
– plot(t,y)
Solving ordinary differential
equations
• Another example to solve a 2nd order ODE, y'' + y' + y + t = 0,
the matlab code yprime1.m should be like,
function yp=yprime1(y,t)
yp(1) = y(2);
yp(2) = -y(2) - y(1) -t;
• Solve it by
– tspan=[0,10];
– y0 = 0;
– [t,y] = ode23(@yprime1,tspan,y0)
• Plot the graph t vs the first and second column of y to show
the solution y and y’
– plot(t,y(*,1),y(*,2))
• Refer to forfun/orbit.m to solve an orbit trajectory using
ode23.
Solve DE below with MATLAB

dy
+ 2y =
12 y (0) = 10
dt
•>> y = dsolve('Dy + 2*y = 12', 'y(0)=10')
•y =
•6+4*exp(-2*t)

•>> ezplot(y, [0 3])


•>> axis([0 3 0 10])
Solve DE below with MATLAB

dy y (0) = 10
+ 2y =
12sin 4t
dt
•>> y = dsolve('Dy + 2*y = 12*sin(4*t)',
'y(0)=10')
•y =
• -12/5*cos(4*t)+6/5*sin(4*t)+62/5*exp(-2*t)

•>> ezplot(y, [0 8])


•>> axis([0 8 -3 10])
Solve DE below with MATLAB

2
d y dy
2
+ 3 + 2y = 24
dt dt
y (0) = 10 y '(0) = 0
•>> y = dsolve('D2y + 3*Dy + 2*y = 24',
'y(0)=10', 'Dy(0)=0')
•y =
•12+2*exp(-2*t)-4*exp(-t)

•>> ezplot(y, [0 6])


Solve DE below with MATLAB
2
d y dy
2
+ 2 + 5y =
20
dt dt
y (0) = 0 y '(0) = 10

•>> y = dsolve('D2y + 2*Dy + 5*y = 20',


• 'y(0) = 0', 'Dy(0) = 10')
•y =
•4+3*exp(-t)*sin(2*t)-4*exp(-t)*cos(2*t)

•>>ezplot(y, [0 5]}
Laplace transform
Syntax
• laplace(F)
• laplace(F,t)
• laplace(F,w,z)
• Description
• L = laplace(F) is the Laplace transform of the
scalar symbol F with default independent
variable t. The default return is a function of s.
The Laplace transform is applied to a function of
t and returns a function of s.
LT Matlab commands
The following Matlab commands are used in order to strengthen
the understanding of LT.

• syms
• laplace
• diff
• ilaplace
Inverse Laplace Transofrm Matlab Command

1 syms s
F (s) = 2 ilaplace(1/s^2)
s

Return
t
Laplace Matlab
Transofrm Command
syms t
f (t ) = t 4
f = t^4

4 laplace(f)
L[t ] Return
s24/s^5

Laplace Transofrm Mathematica Command

LaplaceTransform[Sin[t],t,s]
L[sin(t )]
Laplace Transform MATLAB
Command
f(t) = t4 syms t
f = t^4
laplace(f)
returns
24/s^5
g(t)=sqrt(s) syms s
g = 1/sqrt(s)
laplace(g)
returns
pi^(1/2)/t^(1/2)
f(t) = e–at syms t a x
f = exp(-a*t)
laplace(f,x)
returns
1/(a + x)
Laplace Transform (LT)

• Laplace transform of x(t) = t ,


• >> syms f t
• >> f=t;
• >> laplace(f)
• Pretty Or simplify (f)
• ans =1/s^2
Example – Application of Differentiation

g (t ) = t cos(bt )
l {t cos(bt )} ↔ ?

G ( s) = − F (s)
ds Matlab Code:
∂ s
=− { 2 }; Re( s ) > 0
ds s + b 2

s 2 − b2
= ; Re( s ) > 0
(
s +b
2 2 2
)
Example
e − sb / a
• What is Laplace of t^3? f ( at − b)u( at − b) ↔ F (s / a)
a
– From the table: 3!/s^4 Re(s)>0
Time transformation
• Find the Laplace Transform:
g (t ) = sin(12t − π / 2)u (4t − π / 6)
g (t ) = sin{3(4t − π / 6)}u (4t − π / 6) = sin(3τ )u (τ ) τ = 4t −π / 6
Time _ Translation :
a = 4; b = π / 6
e − sπ / 24
G (s) = F ( s / a ); Note that without u(.) there will
4 be no time translation and thus,
3 the result will be different:
f (τ ) = sin(3τ )u (τ ) ↔ F ( s ) =
s2 + 9
e − sπ / 24 3
G (s) = ;
4 ( s / 4) + 9
2

Assume t>0
Inverse of LT

• inverse Laplace transform of F(s)=24/s(s+8)


• >> syms F S
• >> F=24/(s*(s+8));
• >> ilaplace(F)
• ans =
• 3-3*exp(-8*t)
The inverse transform can also be computed using
MATLAB. If you want to compute the inverse
Laplace transform of 24
F (s) =
s ( s + 8)
you can use the following command lines.
>> syms F S
>> F=24/(s*(s+8));
>> ilaplace(F)
ans =
3-3*exp(-8*t)
OR
6*exp(-4*t)*sinh(4*t)
Dr. Nassereldeen A. Kabbashi BTE4415
Partial fraction

• find the partial-fraction expansion of


2 2
• Y(s)=4s +4s+4/s2(s +3s+2)
• >> 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:
Pretty answer
• 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)
Model representations

Three Basic types of model representations for continuous LTI systems:

• Transfer Function representation (TF)

• Zero-Pole-Gain representation (ZPK)

• State Space representation (SS)

! More help is available for each model representation by typing:


help ltimodels

92
Transfer Function representation

Y (s ) 25
Given:
=
G (s ) = 2
U (s ) s + 4s + 25

Matlab function: tf

Method (a) Method (b)

num = [0 0 25]; s = tf('s');


den = [1 4 25]; G = 25/(s^2 +4*s +25)
G = tf(num,den)

93
State Space representation

 1 0  1
Given: =x& ,Ax + =
Bu A =  B 0 
  −2 1   
=y Cx + Du
C=[3 −2] D = [0 ]
Matlab function: ss

A = [1 0 ; -2 1];
B = [1 0]’;
C = [3 -2];
D = [0];
sys = ss(A,B,C,D)

94
THANK YOU
Prof Kabbashi
International Islamic University Malaysia
KOE/BTE Eng/BERC

Вам также может понравиться