Sunteți pe pagina 1din 17

Lab # 4 Introduction to MATLAB and Simulink, Solution of

Differential Equations Using MATLAB and Simulink and Transfer


Function Based Modelling

Objectives
To evaluate and analyse transfer functions in MATLAB and to implement control systems in
MATLAB using Simulink.

Pre Lab

Introduction:
Typically, control engineers begin by developing a mathematical description of the dynamic
system that they want to control. The system to be controlled is called a plant. This plant is
normally represented in some form for controlling it.

MATLAB Functions:
Important MATLAB functions used for building linear models include:

sys = tf(num,den) % Transfer function

sys = zpk(z,p,k) % Zero/pole/gain

sys = ss(a,b,c,d) % State-space

sys = frd(response,frequencies) % Frequency response data

% is used to write comments in MATLAB.

Explore these functions from help of the MATLAB and construct your models.
Linear Model Representations:
Normally four types of representations are used in MATLAB for representing linear models.
These are presented here with the examples:

Transfer function representation


A continuous-time Single Input Single Output (SISO) transfer function in polynomial form is
given by:

where s is the Laplace variable, N(s) is the numerator polynomial, and D(s) is
the denominator polynomial.
Create a SISO transfer function model in polynomial form using:
G = tf(num,den)
where num and den are row vectors of coefficients of the polynomials N(s)
and D(s), respectively. These row vectors are ordered in descending powers
of s. G is a tf model object.
For example, create the transfer function G(s) = s/(s2 + 2s + 1), using
G = tf([1 0],[1 2 1]);
Alternatively, you can specify the same tf model as a rational expression in
the Laplace variable s:

s = tf('s'); % Define the Laplace variable


G = s/(s^2 + 2*s + 1); % Specify rational expression in s
Zero Pole gain models

A continuous-time SISO transfer function in factorized (zero-pole-gain) form


is given by:

where:
• k is a real- or complex-valued scalar gain.
• z1 ,..., zm are the real or complex conjugate pairs of zeros of the transfer
function G(s) — roots of the numerator polynomial N(s).
• p1 ,..., pn are the real or complex conjugate pairs of poles of the transfer
function G(s) — roots of the denominator polynomial D(s).

Pre Lab Task


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
RESULTS:

Figure 1 : Simulink diagram for the given electric system .

The above figure describe the Simulink implementation of the circuit given in prelab task. The
Simulink implementation is very easy as compare to solve the circuit on paper as it could have
differentials in the resultant equation and very difficult to handle.

Figure 2 : Simulink output graph for the unit step input signal .
In the above figure we apply the unit step signal as input signal and observe the output as y(t) on
the scope , we see that signal start to charge when apply the signal and after some time it
maintain the constant 1 position .

Figure 3 : Simulink output graph when the input is impulse signal .

For the above output graph we use the impulse as the input signal and then observe the circuit
output as in the case of impulse signal. The capacitor charge to very low voltage and then return
back to the 0 condition.
Figure 4 : Simulink output graph when the ramp signal is applied as input .

Above figure represent the output voltage when the input signal is a ramp signal . when the value
of the ramp signal starts from 0 and goes on the output voltage turn in to a parabola shape and
goes on increases as the ramp signal value increases.

Figure 5 : Simulink output graph when the sinesoidal signal is applied as input .
Above figure represents the output voltage (vo) graph when the applied signal is of sinusoidal
nature. As the input is of sine nature the output in return also represents the sinusoidal signal but
the value or amplitude of the signal decreases in the output case .

In-Lab Task :

Task 01:
Use MATLAB and the SymbolicMath Toolbox to find the Laplace transform of the
following time functions:

a. f(t)=8t2 cos(3t+45)
b. f(t)=3te-2t sin(4t+60)

A:
MATLAB CODE:
clear all
close all
clc
syms t s;
Ft=8*(t^2)*cos((3*t)+45);
LAPFunction=laplace(Ft)

RESULTS :

LAPFunction =

(16*(3*sin(45) - s*cos(45)))/(s^2 + 9)^2 - (64*s^2*(3*sin(45) - s*cos(45)))/(s^2 + 9)^3 -


(32*s*cos(45))/(s^2 + 9)^2
B:
MATLAB CODE:
clear all
close all
clc
syms t s;
Ft=3*t*exp(-2.*t)*sin((4*t)+60);
LAPFunction=laplace(Ft)

RESULTS:

LAPFunction =

(3*(2*s + 4)*(4*cos(60) + sin(60)*(s + 2)))/((s + 2)^2 + 16)^2 - (3*sin(60))/((s + 2)^2 + 16)

Task 02:
Use MATLAB and the Symbolic Math Toolbox to find the inverse Laplace transform of the
following frequency functions:

a.

(𝑠 2 + 3𝑠 + 10)(𝑠 + 5)
G(s) =
(𝑠 + 3)(𝑠 + 4)(𝑠 2 + 2𝑠 + 100)

MATLAB CODE :

clear all
close all
clc
syms s t
g1=(s+5)*(s^2+3*s+10);
g2=(s+3)*(s+4)*(s^2+2*s+100);
g=g1/g2;
Function=ilaplace(g)

RESULTS:
Function =

(20*exp(-3*t))/103 - (7*exp(-4*t))/54 + (5203*exp(-t)*(cos(3*11^(1/2)*t) -


(11^(1/2)*sin(3*11^(1/2)*t))/57233))/5562

b.

𝑠 3 + 4𝑠 2 + 2𝑠 + 6
G(s) =
(𝑠 + 8)(𝑠 2 + 8𝑠 + 3)(𝑠 2 + 5𝑠 + 7)

MATLAB CODE :
clear all
close all
clc
syms s;
g1=((s^3)+4*(s^2)+2*s+6);
g2=(s+8)*((s^2)+8*s+3)*((s^2)+5*s+7);
G=g1/g2;
Function=ilaplace(G)

RESULTS:

Function =

(1199*(cosh(13^(1/2)*t) - (4262*13^(1/2)*sinh(13^(1/2)*t))/15587))/(417*exp(4*t)) -
(65*(cos((3^(1/2)*t)/2) + (131*3^(1/2)*sin((3^(1/2)*t)/2))/15))/(4309*exp((5*t)/2)) -
266/(93*exp(8*t))
Task 03 :
Consider the following RLC circuit (Fig 4.3) and take the following values R=2Ω, L=1H,
and 1/LC=25.

Figure 4.3 RLC circuit for Task 3

a. Write the differential equation for the network if v(t)=u(t), a unit step.
b. Solve the differential equation for the current, i(t), if there is no initial energy in the
network.
c. Make a plot of the solution i.e. plot current (i) versus time (t).

MATHEMETICAL MODEL:

−𝑣𝑖 + 𝑣𝑅 + 𝑣𝐿 + 𝑣𝐶 = 0

𝑣𝑖 = 𝑣𝑅 + 𝑣𝐿 + 𝑣𝐶
𝐿𝑑𝑖 𝑖
𝑣𝑖 = 𝑖𝑅 + + 𝑐 ∫ 𝑖. 𝑑𝑡
𝑑𝑡

𝑑𝑣𝑖 𝑑𝑖 𝐿𝑑2𝑖 1
= 𝑑𝑡 . 𝑅 + + 𝑐.𝑖
𝑑𝑡 𝑑𝑡 2
SIMULINK DIAGRAM:

Figure 6 : Simulink circuit diagram for the above given circuit .

Above figure represents the Simulink circuit implementation of the above given circuit to find
the relation between resultant current i(t) and applied voltage vi(t).first we find the input voltage
and output current relationship in which exclude all the other veriable factors.

RESULTS :

Figure 7 : Output graph of the output voltage and input voltage relation .
Above graph represents the output current which is related to the input voltage signal vi(t) .first
this graph goes as straight line and after some time period it fall back and almost approaching a
constant value after some time.

Task 04 :

(1) Use MATLAB to generate the transfer function:

5(𝑠+15)(𝑠+26)(𝑠+72)
G(s)= 𝑠(𝑠+55)(𝑠2 +5𝑠+30)(𝑠+56)(𝑠2 +27𝑠+52)

In the following ways:


a. The ratio of factors.

MATLAB CODE :

clear all
close all
clc
syms s;
g1=5*(s+15)*(s+26)*(s+72);
g2=s*(s+55)*((s^2)+5*s+30)*(s+56)*((s^2)+27*s+52);
a=conv([0 5],[1 15]);
b=conv([1 26],[1 72]);
c=conv(a,b)
a1=conv([1 0],[1 55]);
b1=conv([1 5 30],[1 56])
c1=conv(a1,b1);
d1=conv(c1,[1 27 52]);
[R P K]=residue(c,d1)
RESULTS:
R=

0.0203

0.0068

-1.8470 - 0.4850i

-1.8470 + 0.4850i

3.6669

P=

-56.0000

-24.9127

-2.5000 + 4.8734i

-2.5000 - 4.8734i

-2.0873

K=

[]

b. Use MATLAB to generate the partial-fraction expansion of the following function:

104 (𝑠+5)(𝑠+70)
F(s)=𝑠(𝑠+45)(𝑠+55)(𝑠2 +7𝑠+110)(𝑠2 +6𝑠+95)
MATLAB CODE :
clear all
close all
clc
syms s
g1=[10000 750000 3500000];
g2=[1 498 23272 123740 2259625 2678500 25863750];
[R P K] = residue(g1,g2)

RESULTS:
R=

-0.0001

-0.0045

-0.1810 + 0.1575i

-0.1810 - 0.1575i

0.1833 - 0.3084i

0.1833 + 0.3084i

P=

1.0e+002

-4.4647

-0.4814

-0.0135 + 0.0924i

-0.0135 - 0.0924i

-0.0034 + 0.0370i

-0.0034 - 0.0370i

K=

[]
DISCRIPTION:
In this we perform the Differential equation modelling using the MATLAB code
and Simulink . As the differential equations are quite complex to solve them on paper rather it is
very easy we just put the differential equation in the MATLAB code and we get the solved
equation. So this lab basically related to thes kind of implementation and operations on transfer
function. Transfer function is the laplace transform of the system impulse response .we first find
the Laplace transform of the imupluse response and see how we get the transfer function in the
MATLAB code and then we perform the inverse operation to get the impulse response from the
transfer function by using the inverse Laplace transform.then we see the other method in
MATLAB to solve the differential equztion in term of modelling in Simulink and observe the
output for the various input signal . Simulink is rather quite easy as compared to MATLAB code
, we just have to make the model by using the integrator summer gain or other peripherals to get
the required circuit.when we make the circuit according to the resultant differential equation we
used the scope to observe the output signal for the applies input signal at various time points.

Post-Lab:
Task:
Solve the differential equation using MATLAB and plot the results.

y ′′(x) + 8y ′ (x) + 2y(x) = cos(x); y(0) = 0, y′ (0) = 1

MATLAB CODE:
clear all
close all
clc
x=0:10;
y=dsolve('D2y+8*Dy+2*y=cos(x)','y(0)=0','Dy(0)=1')
pretty(y)

RESULTS:

y=

cos(x)/2 - (14^(1/2)*exp(t*(14^(1/2) - 4))*(4*cos(x) + 14^(1/2)*cos(x) - 2))/56 -


(14^(1/2)*(14^(1/2)*cos(x) - 4*cos(x) + 2))/(56*exp(t*(14^(1/2) + 4)))
1/2 1/2 1/2

cos(x) 14 exp(t (14 - 4)) (4 cos(x) + 14 cos(x) - 2)

------ - ------------------------------------------------------ -

2 56

1/2 1/2

14 (14 cos(x) - 4 cos(x) + 2)

-----------------------------------

SIMULINK MODEL :

Figure 8 : Simulink circuit model for the above given differential equation .

Above figure represents the Simulink block dizgram for the implementation of the given
differential equation.to find the y(t) by solving this differential equation is quite complex process
so the Simulink diagram is an alterantive best option to observe the output easily.
RESULTANT GRAPH :

Figure 9 : Output simulink graph which represent the resultant y(t) .

Above graph represents the output signal after manipulating the above given differential equation
as y(t).as we applies the input signal as sinusoidal nature the output in return also a sinusoidal
signal with less amplitude due to the expression given for the process.

CONCLUSION :

In this lab we learnt about how we can use the MATLAB to solve the differential equations.as
when we solve any kind of mechanical or electrical system in term of the solution equation we
remains with the differential equations so to solve the differential equation on paper is quite
complex method so the MATLAB give us ease in solving such a differential equation and give the
answers instantly.we also see the SIMULINK modeling in which we model the differential
equation in term of circuit in which we use the integrators to get ride of the differentials and other
peripherals such as sum,gain, product ,scope ,input signal etc.by using the scope we can observe
the effect of output entity with respect to the time .so it is very convenient for us to determine the
output at any instant of time.

S-ar putea să vă placă și