Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Lab No.

Introduction to MATLAB and simulink 4

Objective:
To get an introduction to MATLAB and simulink tool.

Introduction:
MATLAB and SIMULINK

MATLAB® is a high-level language and interactive environment that enables you to perform
computationally intensive tasks- especially matrix operation and computations- faster than with
traditional programming languages such as C, C++, and FORTRAN.

Simulink is an environment for multi-domain simulation and Model-Based Design for dynamic
and embedded systems. It provides an interactive graphical environment and a customizable
set of block libraries that let you design, simulate, implement, and test a variety of time-varying
systems, including communications, controls, signal processing, video processing, and image
processing.

FUNCTION USED:

 [z,p,k] = tf2zpk(b,a) finds the matrix of zeros z, the vector of poles p, and the associated
vector of gains k from the transfer function parameters b and a.
 sys = tf(num,den) creates a continuous-time transfer function with numerator(s) and
denominator(s) specified by numand den. The output sys is a TF object storing the
transfer function data.
 F = ilaplace(L) is the inverse Laplace transform of the scalar symbolic object L with
default independent variable s. 
 [r,p,k] = residue(b,a) finds the residues, poles, and direct term of a partial fraction
expansion of the ratio of two polynomial
 dsolve('eq1','eq2',...,'cond1','cond2',...,'v') symbolically solves the ordinary differential
equations eq1,eq2,... using v as the independent variable. Here cond1,cond2,... specify
boundary or initial conditions or both. You also can use the following
syntax: dsolve('eq1, eq2',...,'cond1,cond2',...,'v'). The default independent variable is t.
Lab No.
Introduction to MATLAB and simulink 4

Lab Tasks:
 Task No. 1:
Problem Statement:
5 s+0.25
G ( s )=
s ( s+1 )( s+2 ) ( s+3)
i. Write transfer function in matlab.
ii. Find Zeros and poles and gain of the transfer function.
iii. Find inverse laplace transform.
Implementation:
num = [5 0.25];
den = conv ([1 1 0],[1 5 6]);
G = tf (num,den);
[r,p,k] = tf2zpk(num,den);
disp('The zeros of the Transfer function are');
disp(r);
disp('The poles of the Transfer function are');
disp(p);
disp('The Gain of the Transfer function is');
disp(k);
syms s t
G1 = (5*s+0.25)/(s*(s+1)*(s+2)*(s+3));
g = ilaplace(G1);
g = simplify(g);
disp('Inverse laplace');
pretty(g)

Results:
The zeros of the Transfer function are
0
0
-0.0500
The poles of the Transfer function are
-3.0000
-2.0000
-1.0000
The Gain of the Transfer function is
5
Inverse laplace

59
- 39/8 exp(-2 t) + 19/8 exp(-t) + -- exp(-3 t) + 1/24
24
Lab No.
Introduction to MATLAB and simulink 4

 Task No. 2:
Problem Statement:
s5 +8 s 4 +23 s 3+ 35 s 2+28 s+3
F ( s) =
s ( s+ 1 )( s+2 ) (s+3)( s+ 4)
i. Find the inverse Laplace.
ii. Find the inverse Laplace using partial fraction.
iii. Compare i and ii.
Implementation:
num = [1 8 23 35 28 3];
den = conv([1 3 2 0],[1 7 12])
F = (s^5+8*s^4+23*s^3+35*s^2+28*s+3)/(s*(s+1)*(s+2)*(s+3)*(s+4));
f = ilaplace(F);
f = simplify (f);
disp('Inverse Laplace is');
pretty (f)
[r,p,k] = residue(num,den);
F1 = (0.125/(s+4))-(3/(s+3))-(0.25/(s+2))+(1/(s+1))+(0.125/s);
f1 = ilaplace(F1);
disp('Inverse Laplace via partial fraction is');
pretty(f1)

Results:

Inverse Laplace is

dirac(t) - 1/4 exp(-2 t) + exp(-t) - 3 exp(-3 t) + 1/8 + 1/8 exp(-4 t)


Inverse Laplace via partial fraction is

1/8 - 1/4 exp(-2 t) + exp(-t) - 3 exp(-3 t) + 1/8 exp(-4 t)


Lab No.
Introduction to MATLAB and simulink 4

 Task No. 3:
Problem Statement:
Solve x’’+x’+3x = t x(0)= -1 and x’(0)=-3
Implementation:

Results:

BY ODE Solvers

eqn2 = ‘D2y + Dy + 3*y = x’;


inits2 = ’y(0)=1, Dy(0)=-3’;
y=dsolve(eqn2,inits2,’x’)
z = eval(vectorize(y));
Lab No.
Introduction to MATLAB and simulink 4

plot(x,z)

Conclusion:
Matlab is very helpful in solving the modeled systems. Once the system is modeled
mathematically in the form of differential equation, matlab can be used easily to find the solution of the
system. Several functions are available for operating on and finding transfer functions. Solutions of
differential equation can be found directly if they are available in their transfer function representation.

Simulink tool provides a drag and drop environment where they mathematically modeled system can
be implemented. The result block diagram can be used to evaluate and plot the forced or/and natural
response of the system to check its characteristics and stability

You might also like