Lab3
Lab3
Group Members:
Abdullah Shafiq: FA20-EPE-077
Muhammad Furqan khan: FA20-EPE-074
Submitted to:
Mam Zainab
Lab
03
A P C
TOTAL MARKS
OBTAINED MARKS
Objective:
The main objective of this lab is to make the students understand how we can calculate the
Laplace transform and inverse Laplace transform. While calculating the inverse Laplace
transform, we often need to solve the partial fractions. MATLAB has a command to obtain the
partial fraction expansion of a function in the form B(s)/A(s).
LAPLACE TRANSFORM
To find the Laplace transform of a function f(t) we know that:
In MATLAB we can use just one command laplace(f(t)) to calculate the Laplace transform.
Lab Task 1:
Find the Laplace transform of the following functions.
s^2 + 3 s + 1
---------------------
s^3 + 3 s^2 + 3 s + 1
Continuous-time transfer function.
2. MATLAB code:
syms s
C= [1 8 23 35 28 3];
D= [1 6 8 0];
b=tf(C, D);
disp(b)
output:
b=
Comments: In MATLAB we can define a transfer function using command ft(function). It will give us
the exact output of the function.
Task 2(b): Find Inverse Laplace transform following time domain signals.
1. G(s)=(5s+3)/(s+1)(s+2)(s+3)
2. G(s)=1/s(s+1)3 (s+2)
Solution:
1. MATLAB code:
syms s
g= (5*s+3)/((s+1)*(s+2)*(s+3));
z=ilaplace(g);
disp('z=')
disp(z)
Output:
z=
7*exp(-2*t) - exp(-t) - 6*exp(-3*t)
2. MATLAB code:
syms s
g= 1/s*(s+1)*3*(s+2);
z=ilaplace(g);
disp('z=')
disp(z)
Output:
z=
9*dirac(t) + 3*dirac(1, t) + 6
3. MATLAB code:
syms s
g3=(4*s^2+16*s+12)/(s^4+(12*s^3)+(44*s^2)+48*s);
z=ilaplace(g3);
disp('z=')
disp(z)
Output:
z=
exp(-2*t)/4 + (3*exp(-4*t))/4 - (5*exp(-6*t))/4 + ¼
4. MATLAB code:
syms s
g4=(100*s+2)/(s*(s^2+4)*(s+1));
z=ilaplace(g4);
disp('z=')
disp(z)
Output:
z=
(98*exp(-t))/5 - (201*cos(2*t))/10 + (49*sin(2*t))/5 + ½
Comments: In Matlab we can find Inverse Laplace transform of a function using command
ilaplace(function). It will give us the exact output of the function.
Task # 03:
B (S) S 2 +2 S +3
1 =
A(S) (s +1)
3
CODE
clc
clear all
close all
syms R P K
A= [1 3 1];
B= [1 3 3 1];
[R P K]=residue(A,B)
output:
B (S) S 2 +2 S +3 1 1 1
= 3 = + -
(
A S ) (s +1) s +1 s +1 s +1
MATLAB CODE :
clc
clear all
close all
syms R P K
d=[1 6 8 0];
n=[1 8 23 35 28 3];
[R P K]=residue(d,n);
output:
r= [ -0.0030 + 0.0000i -0.0234 + 0.0000i 0.0357 - 0.3453i 0.0357 + 0.3453i -
0.0449 + 0.0000i]
P= [-4.0341 + 0.0000i -2.0787 + 0.0000i -0.8810 + 1.4427i -0.8810 - 1.4427i -
0.1252 + 0.0000i]
k=[]
MATLAB CODE;
clc
clear all
close all
syms R P K
d=[1 12 44 48 0];
n=[4 16 12];
[R P K]=residue(n,d);
output:
R=[ -1.2500 0.7500 0.2500 0.2500]
P= [-6.0000-4.000 -2.0000 0]
k=[]
−1.2500 0.7500
= + + 0,2500
s+ 6 s+ 4 s +2
0.2500
+
s
Comment: In MATLAB we can define the residue command can also be used to form the
polynomials (numerator and denominator) from its partial fraction expansion
Question: Using MATLAB find the transfer function G(s)=Vo(s)/Vi(s). (Mesh Analysis
I3
i1 I2
Mesh Analysis:
Applying KVL on LOOP1 of circuit.
V(s)=(2+2s)i1+(-1-2s)i2-i3 …………..(1)
Similarly
Applying KVL on LOOP2 of circuit.
(-1-2s)i1+(7+5s)i2+(-2-3s)i3=0 ……….(2
Similarly
-i1+(-2-3s)i2+(1+1/5s+3s)i3=0 ……… (i3
From crammer rule
MATLAB code:
%Using MATLAB find the transfer function G(s)=Vo(s)/Vi(s). (Mesh
Analysis
syms I V z s i1 i2 i3 v
I=[i1;i2;i3];
V=[v;0;0];
z=[2+(2*s) -1-(2*s) -1; -1-2*s 7+(5*s) -2-(3*s); -1
-2-(3*s) 3+(3*s)+1/(5*s)];
z1=[2+(2*s) v -1; -1-2*s 0 -2-(3*s); -1 0 3+(3*s)
+1/(5*s)];
A1=(det(z1));
A=(det(z));
i2=A1/A;
Vout=i2*4;
disp('Vout')
disp(Vout)
G=Vout/V;
disp('G(S)=')
disp(G)
OUTPUT:
Vout
(4*v*(30*s^3 + 60*s^2 + 27*s + 1))/(120*s^3 + 246*s^2 + 120*s + 13)
G(S)=
[ (4*(30*s^3 + 60*s^2 + 27*s + 1))/(120*s^3 + 246*s^2 + 120*s + 13), 0, 0]
Task: Explain the results obtained and comment on the speed of the vehicle.
create a MATLAB-function cruise_speed.m
function dvdt=cruise_speed(t, v)
%flow rate M=750; %(Kg)
Fv=30; %( Nsec/m) Fa=300;
%N
% dv/dt=Fa/M-Fv/M v
dvdt=Fa/M-Fv/M*v;
6
speed
0
0 20 40 60 80 100 120 140 160 180 200
time
Explanation;
Cruise control:
It is the system that automatically control the speed of the vehicle by adjusting the throttle
position.
Ode45 function is used to find the velocity of the vehicle. It integrates the function
(cruise_speed) which is first order differential equation, from t= [0 200] seconds.
General form: