0% found this document useful (0 votes)
15 views

Lab3

Uploaded by

ammaradil817
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Lab3

Uploaded by

ammaradil817
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

SUBJECT: control system

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.

MATLAB Code: clc


clear all
close all
1. g1(t)= sin(?t)
syms t a
g1=sin(w*t);
a=laplace(g1);
disp('Laplace of g1(t)= sin(?t)')
disp(a)
OUTPUT:
Laplace of g1(t)= sin(?t)
w/(s^2 + w^2)
2. g2(t)=sin( 20t)
g2=sin( 20*t);
b=laplace(g2);
disp('Laplace of g2(t)=sin( 20t)')
disp(b)
Output:
Laplace of g2(t)=sin( 20t)
20/(s^2 + 400)
3. g(t)=t^2
g3=(t^2);
c=laplace(g3);
disp('Laplace of g(t)=t^2')
disp(c)
Output: Laplace of g(t)=t^2
2/s^3
4. g(t)=e^at
g4=(exp(a*t));
d=laplace(g4);
disp('Laplace of g(t)=e^at')
disp(d)
Output: Laplace of g(t)=e^at
-1/(a - s)
5. g(t)=te^-5t
g5=t*(exp(-5*t));
e=laplace(g5);
disp('Laplace of g(t)=te^-5t')
disp(e)
Output: Laplace of g(t)=te^-5t
1/(s + 5)^2
6. g(t)=2e^-2t*sin(2t)
g6=2*(exp(-2*t).*sin(2*t));
f=laplace(g6);
disp('Laplace of g(t)=2e^-2t*sin(2t)')
disp(f)
Output:
Laplace of g(t)=2e^-2t*sin(2t)
4/((s + 2)^2 + 4)

Comments: In MATLAB we can find Laplace transform of a function using command


Laplace(function). It will give us the exact output of the function.
Task2: Define the following transfer functions in MATLAB.
1. MATLAB code:
syms s
B= [1 3 1];
A= [1 3 3 1];
a=tf(B,A);
disp(a)
output:
a=

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=

s^5 + 8 s^4 + 23 s^3 + 35 s^2 + 28 s + 3


----------------------------------------
s^3 + 6 s^2 + 8 s
Continuous-time transfer function.
3.MATLAB code:
syms s
A= [4 16 12];
B= [1 12 44 4a8 0];
a=tf(B, A);
disp(a)
output:
a=

s^4 + 12 s^3 + 44 s^2 + 48 s


----------------------------
4 s^2 + 16 s + 12

Continuous-time transfer function.

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:

R=[1.0000 1.0000 -1.0000] p=[-1.0000 -1.0000 -1.0000]


k=[]

B (S) S 2 +2 S +3 1 1 1
= 3 = + -
(
A S ) (s +1) s +1 s +1 s +1

B (S) S 5 +8 s4 + 23 s 3+35 s2 +28 s+3


 =
A(S) 3 2
s +6s +8s

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=[]

B (S) S 5 +8 s4 + 23 s 3+35 s2 +28 s+3


 = =
A(S) 3
s +6s +8s
2

−0.0030+0.0000 i 0.0234+0.0000 i 0.0357−0.3453 i 0.0357+0.3453 i


- + +
s +4.0341+0.0000 i s +2.0787+0.0000 i s +0.8810+1.4427 i s +0.8810−1.4427 i
-
0.0449+ 0.0000i ¿ ¿
s+ 0.1252+ 0.0000 i

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;

2_ create a new MATLAB m-file and write

v0= 0; %(initial speed) [t,v]=ode45('cruise_speed', [0


200],v0); plot(t,v); grid on;
title('cruise speed time response to a constant traction force Fa(t) ')
Figure
cruise speed time response to a constant traction force Fa(t)
10

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:

[TOUT, YOUT] = ode45(ODEFUN, TSPAN, Y0)

 Where, TSPAN = [T0 TFINAL]


 It integrates the system of differential equations y' = f (t, y) from time T0 to TFINAL
 with initial conditions Y0. ODEFUN is a function handle.

You might also like