Control Systems
CPE325
Lab 02
Name Waqar Asif
Registration
CIIT/FA19-BCE-022/ISB
Number
Class BCE-6A
Instructor’s Dr. Ali Khaqan
Name
Lab #2 Introduction to MATLAB and Simulink, Solution of
Differential Equations Using MATLAB and Simulink and Transfer
Function Based Modelling
Pre Lab Tasks:
1. Implement above example in SIMULINK
2. Find Response of the system for following Inputs;
a. Unit Step
b. Unit Impulse
c. Ramp
d. Sinusoidal
1.
2. Find Response of the system for following Inputs;
a. Unit Step
b. Unit Impulse
c. Ramp
d. Sinusoidal
In- Lab Task:
Task 1:
s+ 0.25
G(s)=
s ( s +1 ) ( s+ 2 ) (s +3)
Considering G(s), prove that tf2zp() and zp2tf() are inverse of each other. Also, prove that
laplace() and illaplace() exhibits the same property.
Code:
clc;
close all;
clear all;
z = 0.25;
p = [0 1 2 3];
k = 1;
G1 = zpk(z,p,k)
[num ,den] = zp2tf(z,p,k)
[zeros,poles,k] = tf2zp(num,den)
syms s;
fun = (s+0.25) / (s*(s+1)*(s+2)*(s+3));
x = ilaplace(fun);
pretty(x)
y = laplace(x);
pretty(y)
Task 2:
Find inverse Laplace transform f(t) & hence find inverse from partial fraction form(use
MATLAB to compute the residues). Where
5 4 3 2
s + 8 s +23 s +35 s +28 s +3
F (s )= 3 2
s +6 s +8 s
Code:
clc;
close all;
clear all;
syms s;
fun = ((s^5)+(8*s^4)+(23*s^3)+(35 * s^2)+(28*s)+3) / ((s^3)+(6*s^2)+(8*s)) ;
y = ilaplace(fun)
pretty(y);
[zeros,poles,k] = residue([1 8 23 35 28 3] , [1 6 8])
Task 3:
Consider the following RLC circuit (Fig 2.3) and take values of your choice. Make a
mathematical equation of this circuit (taking your own defined values) and then make its
SIMULINK block diagram
Figure 2.3 RLC circuit for Task 3
Code:
Post-lab Task:
Task 01:
Solve the differential equation to compute x(t)
X’’ + 2X’ + 10X = t2
Solution:
Task 02:
Use the mathematical model, computed in In-lab task 02, and find its state space
representation using MATLAB.
Code:
clc;
close all;
clear all;
Fun = tf([1 8 23 35 28 3],[1 6 8 0])
y = ss(Fun)
Critical Analysis:
In this lab, We learnt about the Solution differential equation and Transfer
function-based modelling by using MATLAB and Simulink. We learnt the use
of different function Such as Transfer Function ( tf ) , Zero/pole/gain(z,p,k) ,
State-space ( ss ) and Frequency response data ( frd). We can find the laplace
and inverse laplace of differential equation by using different functions.
Simulink provides graphical environment for modelling , simulating, and
analysing of dynamic systems. A MATLAB code can be generated from a
Simulink model.
Performance Viva
Total/15
(10 Marks) (5 Marks )
Performance /6
Results /3
Critical Analysis /1