Documente Academic
Documente Profesional
Documente Cultură
AbstractA large number of diverse engineering package has been selected because of its general purpose
applications are frequently modeled using different nature and its extensive use in modeling, simulation and
approaches, viz., a differential equation or by a transfer analysis of dynamics systems.
function and state space. All these descriptions provide a
MATLAB is a general purpose commercial
great deal of information about the system, such as
simulation package used to perform numerical and
stability of the system, its step or impulse response, and
symbolic computation. Generally, it is used to solve
its frequency response.
differential equations quickly and easily in an effective
The present paper addresses different approaches used to manner. It also leads to a visual plot of the results [5-10].
derive mathematical models of first and second order Engineering simulation using graphical programming
system, developing MATLAB script implementation tool Simulink plays a vital role in understanding and
and building a corresponding Simulink model. The assessing the operation of a system. Simulink, built upon
dynamic analysis of electric circuit and system using MATLAB, is a powerful interactive tool for modeling,
MATLAB/Simulink has been investigated using simulating and analyzing dynamical system; thus,
different approaches for chosen system parameters. forming an ideal tool for qualitative and quantitative
analysis of electrical and electronic network study. It has
been identified as an ideal tool for laboratory projects,
Index TermsMathematical Model, System Dynamics, and has hence been adopted for teaching a variety of
MATLAB, ODE, Electric Circuit, Simulink, Symbolic courses in electrical and electronics engineering. The
Computation, Transfer Function benefits of MATLAB and Simulink have been well
documented by several workers [11-18].
The present work is an implementation of MATLAB
I. Introduction text based description m.file, graphical programming
Simulink model; and data driven modeling using
Differential equations play a pivotal role in diverse MATLAB and Simulink together. The MATLAB script
fields like mathematics, physics, electrical, mechanical implementation is a text based m.file description of
& civil engineering and biological population modeling system under reference that can be written in any text
etc. They form a powerful means of modeling several editor. The graphical approach uses Simulink model in
engineering and scientific problems. The diversity of terms of block diagram realization for visualizing
engineering applications employing these equations system dynamics. A Simulink model for a given
results into differential equations of different orders. A problem can also be constructed using building blocks
differential equation is a mathematical equation for an from the Simulink library. The model consists of various
unknown function of one or several variables that relates blocks from Simulink libraries arranged in a desired
the value of the function itself and its derivatives of fashion, offering solution to various problems without
various orders [1]. It is well evident that ordinary having to write any codes.
differential equations (ODE) play a vital role in circuit
and system analysis, which in turn play a fundamental The work presented here can be implemented to
role in the modern technological system. Electric circuits investigate the response of other similar engineering
are systems that can be described in different ways using applications. One can implement the MATLAB script
differential equations of first, second and higher order. and Simulink model presented here as a computational
Often, electric systems are modeled using different project based model in circuit and system course, that
approaches such as a differential equation, or by a can contribute to an improvement in learning and
transfer function and state space. Any of these ultimately to educational success in engineering program.
descriptions can provide information about the system In this study, the same has been demonstrated by
dynamics [2-4]. In this study, MATLAB/Simulink considering an example of 1st order electric system. The
behavior of second order system has also been
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
2 MATLAB/Simulink Based Study of
Different Approaches Using Mathematical Model of Differential Equations
investigated for step excitation for various values of Taking Laplace transform of (3) and rearranging, the
damping ratio. system function is given as:
The organization of the present paper involves a brief 1 1
introduction, followed by Section 2 which focuses on Vc ( s )
1
RC (4)
mathematical modeling of first order system. Section 3 Vi ( s) ( sRC 1) ( s 1
) (s )
1
and Section 4 describe selection of system parameters,
and response analysis of first order electric circuit using
RC
MATLAB with different approaches. Section 5 deals where RC is the time constant of the system.
with various approaches for analysis of first order
system using Simulink. Section 6 summarizes data Looking at RC circuit, current as being the output and
driven modeling followed by result and discussion in voltage across the capacitor as state variables, the state
Section 7. Section 8 describes the scope of work in variable representation of the RC circuit is given as:
diverse engineering applications; and finally, Section 9 .
emphasizes on implementation of work presented in this dvc (t ) 1 1
study using Scilab/Xcos as an alternative to dt RC vc (t ) RC vi (t ) (5)
MATLAB/Simulink; followed by a conclusion in
Section 10. The current across the circuit is
1 1
II. Mathematical Modeling of RC System i (t ) vc (t ) vi (t ) (6)
R R
One of the first engineering applications that students
always practice is first order series RC electric circuit. The matrix A B C D for RC series circuit is given
The differential equation governing the series RC circuit as:
of Fig. 1 is given as:
1 1
1 A B
vi (t ) i (t ) R i (t )dt (1) RC RC
C
where vi (t ) is the forcing function; v c (t ) is the 1 1
C D
output voltage across the capacitor; C is the capacitance R R
of the capacitor in Farad; R is resistance of the resistor The mathematical model presented in this section has
in Ohm; and i(t ) is current flowing in the circuit in been implemented using MATLAB/Simulink using
Ampere different approaches for chosen system parameters.
The circuit current i(t ) is given as:
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
MATLAB/Simulink Based Study of 3
Different Approaches Using Mathematical Model of Differential Equations
In the 2nd part of the study, the Simulink models have grid on
been drawn directly using different approaches F1 = laplace(int(10*heaviside(t)),s); %LT of ramp
governing the behavior of series RC circuit. The solution1 = 5*v1+v-F1; %implement DE
mathematical description of the system in Simulink has tf1=solve(solution1,v); %find sol of DE
been translated into block diagram representation using vc_output1=ilaplace(tf1,t); %find v(t)by using IL
the various elements of Simulink block library, and pretty(vc_output1);
finally, the solution of model has been obtained using subplot(3,1,2);
built-in MATLAB solver. ezplot(vc_output1,[0,40]);
title('Voltage versus Time for ramp using LTM');
xlabel('Time');
ylabel('Voltage');
IV. System Response Analysis USING MATLAB grid on
In this investigation, response of first order series RC F2 = laplace(diff(10*heaviside(t)),s); %LT impulse
electric circuit is presented using different approaches. solution2 = 5*v1+v-F2; %differential equation
The effect of varying system parameters is also tf2=solve(solution2, v);
discussed. vc_output2=ilaplace(tf2,t) ; %find v(t) by using ILT
pretty (vc_output2);
subplot (3,1,3);
4.1 Symbolic Simulation Technique, Approach I ezplot(vc_output2,[0,40]);
(Laplace Transform Method) axis([0 40 0 3])
title('Voltage versus Time for impulse using LTM');
In this section, MATLAB symbolic simulation xlabel('Time');
technique using Laplace transform method has been ylabel('Voltage');
employed to solve the model. The Laplace transform grid on
method (LTM) is useful for solving initial value
problems involving linear constant coefficient equations. Fig. 2: MATLAB script for analysis of RC circuit (RC1.m)
In this technique, by using Laplace transform governing,
differential equations are converted into algebraic
equations that can be solved by simple algebraic 4.1.1 Analysis using 'dsolve' commands
technique. The inverse Laplace transform is then applied One can also find the solution of differential equation
to give corresponding function which forms the solution using 'dsolve' functions of symbolic computation. The
to the differential equation. The symbolic built-in MATLAB symbolic function 'dsolve' is used to
commands such as 'laplace', 'ilaplace', and 'heaviside' symbolically solve the ordinary differential equations
functions have been used [5-6, 19-20]. specified by ODE as first argument and the boundary or
The MATLAB script for the mathematical model of initial conditions specified as second argument. In fact,
differential equation (7) using symbolic implementation only one statement 'dsolve' is required to define the
is shown below in Fig. 2. series RC circuit. The other commands are required for
plotting purpose and annotation of graphical output. The
MATLAB Solution MATLAB implementation to solve the (7) using 'dsolve'
function is shown in Figure 3.
% MATLAB script: RC1.m
%Symbolic simulation of (7) of series RC circuit MATLAB Solution
clc; % clear the command window
clear all; % clear all the variables %MATLAB script: RC2.m
close all; %close all figure windows %Symbolic solution of (7) using dsolve function
syms t s v %define symbolic variables clc; %clear command window
v0 = 0; %define IC for v(0) clear all; % clear workspace
vd0 = 0; %define IC for v'(0) close all %close all figure windows
f1=10*(heaviside(t)); %define step signal syms t s v % creating symbolic object
F = laplace(f1, s); %Laplace of step input out=dsolve('5*Dv+v=10*heaviside(t)','v(0)=0');
v1 = s*v - v0; %implement Dv pretty(out);
soltn = 5*v1+v-F; %differential equation subplot(3,1,1);
tf=solve(soltn,v); %solution of equations ezplot(out,[0,40]); % plot of symbolic objects
vc_output=ilaplace(tf,t); %find v(t) by using IL title('Voltage versus Time for step using dsolve');
pretty(vc_output); xlabel('Time');
subplot(3,1,1); ylabel('Voltage');
ezplot(vc_output,[0,40]); % plot of symbolic object ylim([0 12])
ylim([0 12]) grid on
title('Voltage versus Time for step using LTM'); output1=int(out); %finding ramp response
xlabel('Time'); pretty(output1);
ylabel('Voltage' ); subplot (3,1,2);
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
4 MATLAB/Simulink Based Study of
Different Approaches Using Mathematical Model of Differential Equations
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
MATLAB/Simulink Based Study of 5
Different Approaches Using Mathematical Model of Differential Equations
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
6 MATLAB/Simulink Based Study of
Different Approaches Using Mathematical Model of Differential Equations
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
MATLAB/Simulink Based Study of 7
Different Approaches Using Mathematical Model of Differential Equations
1 sVc ( s) Vc ( s) Vi ( s) (17)
L( r (t )) (11)
s2
Converting (17) back to a differential equation, we get
Substituting the (11) in (4), the Laplace transform of
output signal is vc ' (t ) vc (t ) vi (t ) (18)
1
Vc ( s) (12) For computing step response vi (t ) 1 for t 0
s (s 1)
2
Substituting the same in (18), the governing differential
Applying inverse Laplace transform, the ramp equation for step signal is:
response of the system is given as:
vc ' (t ) vc (t ) 1 (19)
t
vc (t ) t (1 e ) for t 0
For computing ramp response vi (t ) t for t 0
In other words, if we have ramp input with slope A1
The governing differential equation for ramp signal is:
i.e vi (t ) A1r (t ) the ramp response is given by
t vc ' (t ) vc (t ) t (20)
vc (t ) A1 (t (1 e )) for t 0
(13)
For computing impulse response
vi (t ) dirac (t ) for t 0
4.4.1.3 Impulse Response
Substituting the same in (18), the governing
Laplace transform of impulse signal is differential equation for impulse signal is:
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
8 MATLAB/Simulink Based Study of
Different Approaches Using Mathematical Model of Differential Equations
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
MATLAB/Simulink Based Study of 9
Different Approaches Using Mathematical Model of Differential Equations
Step4: Connect the appropriate block and customize to develop the Simulink model using (22), firstly, the
each block as desired. Save the model. number of terms inside the differential equation to be
solved is identified. Each term requires a series of
Step5: Make the required changes in the simulation
operation. The Simulink block needed for solving
parameters.
differential equation (22) are dragged from respective
Step6: Run the simulation model and observe the block libraries as per requirement and interconnected to
result. create the model. The various blocks such as signal
generator, step and constant block in source library;
In the forthcoming subsection, the various approaches product and subtraction block in the Simulink math
for solving the first order RC circuit is presented. library; the integrator block in Simulink continuous
library and the scope, To workspace, To file, XY graph
are dragged from sink block library. The integrator is the
5.1 Simulation Model Using Differential Equations, basic building blocks for solving differential equations.
Approaches I The Clock block generates the time and the same is
On solving the (3), the highest derivates term is given copied to workspace. The Simulink model solution for
as: first order differential equation (22) is depicted in Fig.
13. In this Simulink model, one can choose the input
dvc (t )
1
vi (t ) vc (t ) (22)
excitation from signal generator, ramp or impulse using
multiport switch. Depending on numerical constant
dt RC
specified in the control port, one can select the
In this methodology, the differential equation corresponding signal. There is a provision to select
governing the RC electric circuit is arranged as (22) for multiple inputs from signal generator such as sine and
highest order derivates in the left side [22-27]. In order square.
2
Constant2 Simulink model solution for solving DE of series RC circuit
voltage
Signal To Workspace1
Generator
Clock1 Time1 RC.mat
r(t)
Multiport To File2
Ramp Switch u
Impulse u Scope2
Step2 (u-v)
Add1 Scope3
Manual Switch 1/s
Add
Product1 Integrator1
Step1 Measured output
u(t)
RC1.mat
Step
1 v To File1
Constant1 v
R
du/dt
R Divide
Product Derivative
Product2
C Measured current
C
After construction of the model, all system parameters Simulink enables to simulate continuous time system
for model are set by double clicking on each block as either using state space or transfer function of electric
chosen before running simulation. After customization circuit forming the system using individual blocks from
of Simulink model, simulation is performed for specified the Simulink continuous block library.
time period to analyze its behavior. One can visualize
The transfer function of series RC circuit as given by
the input and output plot on the same scope using mux
(4) is:
block as indicated in Scope 2 of model. The 'To
Wokspace' and 'To File' block is used to save the data in 1 1
the Workspace and to MAT files for later processing. Vc ( s )
1
RC
Vi ( s) ( sRC 1) ( s 1
) (s )
1
5.2 Simulation Model Using Transfer Function,
RC
Approach II
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
10 MATLAB/Simulink Based Study of
Different Approaches Using Mathematical Model of Differential Equations
voltage1
To Workspace1
To File2
u u
Ramp
(u-v) Scope2
u
u 1/s
Manual Switch Add
Step
Product1 Integrator1 Measured output1
1
Constant2 Clock
XY Graph
R du/dt
R Divide1 Derivative
Product v
C Product2
Measured current
C 1
R*C.s+1
Input signal Transfer Fcn
Measured input & output
Measured output
Measured input
RC12.mat
To File1
Fig. 16: Simulink flow diagram (RCS4.mdl) of RC Circuit using DE (22) and TF (4)
5.3 Simulation Model Using State Space, Approach set of first order differential equation in terms of state
III variables [28].
Complex electric circuit can be alternatively solved dx
using the system state equation and output equation. Ax Bu (23)
Mathematically, the state of the system is described by a dt
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
MATLAB/Simulink Based Study of 11
Different Approaches Using Mathematical Model of Differential Equations
y Cx Du (24) 1 1
A B
RC RC
The equation (23) represents the state equation and
(24) represents the output equation.
1 1
The variable x represents the state of the system, u C D
is the system input, and y is the output, A is system R R
dynamics matrix representing the coefficient of state
variable, B is the matrix of input representing the The Simulink model solution for (5) and (6) is
coefficient of input in state equation, C is the matrix of depicted in Fig. 17. The model consists of step, ramp,
output representing the coefficient of state variable in manual switch, state space block and scope. In this
model, one can select the input from ramp or impulse
the output equation, D is the direct exposure matrix
block using manual switch 1. There is a provision to
input to output. The matrix A , B , C , D for RC series select step input or ramp and impulse signal using
circuit can be obtained directly and is given as: manual switch.
Ramp1
u
u x' = Ax+Bu
Manual Switch1
y = Cx+Du
u Manual Switch State-Space Scope2
Step3 Impulse
Add1 Scope3 simout
To Workspace
Step2
Step1
Fig. 17: Simulink flow diagram (RCS5.mdl) setup using SS
5.4 Modified Simulink Model using Transfer both are used together. There is a provision to visualize
Function and State Space Together system dynamics using step, ramp or impulse signal.
Using multiport switch one can select the desired input.
The modified form of Simulink model using transfer
The selected input signal is applied simultaneously
function and state space approach is shown in Figure 18.
through state space and transfer function block using
In this model transfer function and state space block
manual switch.
2
Constant
Clock1 Time1
Signal
Generator
u
Ramp Scope2
Multiport
x' = Ax+Bu
Switch simout
y = Cx+Du
State-Space To Workspace
Impulse u
Step3
Add1 Scope3 Manual Switch
1 Scope
Step2 R*C.s+1
Transfer Fcn
u
Step1 Scope4
Fig. 18: Simulink flow diagram based on state space representation (RCS6.mdl)
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
12 MATLAB/Simulink Based Study of
Different Approaches Using Mathematical Model of Differential Equations
5.5 Simulink Model Implementation Using User Alternatively, one can develop Simulink model of the
Defined Functions Library series RC circuit using the Fcn Block of User-Defined
Functions Library of Simulink packages. The Simulink
5.5.1 Alternative Model Development Using Fcn
flow diagram set up using the fcn block is shown in Fig.
Blocks, Approaches IV
19.
voltage 1
To Workspace1
To File2
r(t)
Ramp
u
Scope2
v v
Manual Switch f(u) 1/s
u(t) u(3)(u(1)-u(2)) Integrator 1 Measured Output
Step
1 Clock
Constant1 XY Graph
v
R du/dt
R Divide1 Derivative
Product Product2
C Measured Circuit Current
C
Fig. 19: Simulink model of (22) using Fcn block (RCS7.mdl)
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
MATLAB/Simulink Based Study of 13
Different Approaches Using Mathematical Model of Differential Equations
The Simulink model for S-function file is depicted in waveform both are visualized on the scope. In the model,
Figure 21. To incorporate an S-function into a Simulink the impulse response is obtained by differentiating the
model, the S function block from the User-Defined step response, and ramp response is obtained by
Functions Library is dragged into the model window. integrating the step signal.
The name of the S-function is specified in the S-function
name field of the S-functions blocks in dialog box.
5.5.3 Time Domain Model Development, Approaches
V
The Simulink may be easily adopted in representing
time domain response using various elements of
Simulink block library. The corrosponding step,
impulse and ramp response for the chosen design
paramater is given as:
t
10 5
vc (t ) e (24)
5
t
vc (t ) 10(t 5(1 e )) 5
(25)
Fig.21: Simulink model using S-function block (RCS8.mdl)
u(t) 1
5s+1
Step Transfer Fcn Step Response
1 Step
10
Constant 1 Ramp
Add Gain1 s
u
-K- e Integrator
Impulse Scope 2
Clock Gain 1/RC Math du /dt
Function 5
Gain5 Derivative
Scope 3
-K-
Add1 Gain4 Ramp Response
Fig. 22: Simulink model (RCS9.mdl) using time domain mathematical model of (23), (24) and (25) and transfer function block given by (4)
The Simulink model consists of clock blocks which obtained here using transfer function block and is
generate time index vector, gain block, math function depicted on the scope named Step Response. The lower
block, add block, integrator and derivative block. These part of the model consist of time domain implementation
blocks are dragged from the respective libraries, of step, impulse and ramp response and is displayed on
interconnected, and customized to set the model scope 2,3,4 respectively. On block named scope 2, along
paramaters. The upper part of the model consists of step, with step response the ramp and impulse response is
transfer function and scope. The step response is obtained using integration and derivatives blocks as
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
14 MATLAB/Simulink Based Study of
Different Approaches Using Mathematical Model of Differential Equations
depicted in the model. The impulse response is obtained 6.1 Directly From MATLAB Command Window
by taking derivatives of step response, and the ramp
In this approach, firstly the chosen system parameter
response is obtained by integration of step response.
variables are set in the functional parameters dialog box
window for desired block of the model. The variable
referred in functional parameters dialog window of the
VI. Data Driven Modeling model are specified in the command window and
simulation model is run from Simulink. An alternative
One can use Simulink together with MATLAB in Simulink model having the system parameters R, C
order to specify data and parameters to the Simulink specified in Simulink model transfer fcn block and U
model. In data driven modeling, one can specify the specified in step block functional parameter is depicted
system parameters commands in the MATLAB in Fig. 23.
command window or as commands in an m.file in
MATLAB script. The two cases are presented here:
Scope
Unit step
1
Step R*C.s
Transfer Fcn Step Response
Add
Scope 1
Unity Feedback
C du /dt
Gain Derivative 1
Scope 2
1 Ramp
s 1
Integrator R*C.s
Ramp Response
Add 2 Transfer Fcn 2 Scope 4
Unity Feedback
C du /dt
Gain 1 Derivative 2
Measured Current
Fig. 23: Simulink model simulated from the command window (RCS10.mdl)
The system variables defined in the command 6.2.1 MATLAB Script to Run the Simulink Model
window are as follows:
The MATLAB script used to call Simulink model of
>>R=2.5e3 RCS10.mdl is shown in Fig.24. The MATLAB script
RC_modelcall.m file defines system parameters,
>>C=0.002
executes the simulation for given parameters, and plots
>>U=10 the result. One can quickly change parameters of the
model to simulate multiple cases through script file.
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
MATLAB/Simulink Based Study of 15
Different Approaches Using Mathematical Model of Differential Equations
xlabel('Time'); 10
Voltage
ylabel('Current'); 5
2
response 1
plot(ScopeData2(:,1), 0
0 5 10 15 20 25 30 35 40
ScopeData2(:,3),'m.','LineWidth',1) Time
xlabel('Time');
Fig. 25: Simulation result using symbolic simulation of (7) using LTM
ylabel('Voltage'); with step, ramp and impulse signal (RC1.m)
title ('Voltage versus time for ramp excitation');
legend('ramp Input','ramp Response')
Voltage versus Time for step using dsolve
axis ([0 40 0 400])
10
Voltage
grid on 5
subplot(2,2,4) 0
% plot time index vector versus ramp current response 0 5 10 15 20
Time
25 30 35 40
xlabel('Time'); 300
Voltage
200
ylabel('Current'); 100
0
title ('Current Response of RC circuit for ramp 0 5 10 15 20 25 30 35 40
Time
excitation'); Voltage versus Time for impulse using dsolve
grid on % put grid on the axis 3
Voltage
2
Fig. 24: MATLAB script (RC_modelcall.m) used to call Simulink 1
Model RCS10.mdl 0
0 5 10 15 20 25 30 35 40
Time
15 Step, R=2K
Step, R=5K
Step, R=20K
10
Voltage
0
0 5 10 15 20 25 30 35 40
Time
Fig. 27: Voltage across capacitor for different R using (RC3.m)
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
16 MATLAB/Simulink Based Study of
Different Approaches Using Mathematical Model of Differential Equations
Fig. 27 shows the voltage across capacitor for R=2, 5 The voltage across resistor for R=2, 5 and 20 K Ohm,
and 20 K Ohm respectively using step excitation. The respectively is depicted in Figure 28.
variation in R implies the variation in time constant of
Fig. 29 shows the current across resistor for different
the circuit. It is observed from Figure 27 that the larger
R=2, 5 and 20K Ohm respectively.
is the time constant, slower is the response.
6
Voltage
0
0 5 10 15 20 25 30 35 40
Time
-3
x 10 Current i(t) for R=2, 5 and 20K are
6
Current, R=2K
Current, R=5K
5
Current, R=20K
4
Current
0
0 5 10 15 20 25 30 35 40
Time
It is observed that symbolic solution obtained using The running of script file (RC5.m) by typing the file
Laplace transform method of MATLAB script 'RC1.m' name RC5 without having .m suffix in the command
fully agrees with the plot generated using dsolve prompt, result into a solution that is graphically depicted
function of script 'RC2.m'. in Fig. 31.
Upon executing the MATLAB calling script (RC4.m), Step response
12
the result of MATLAB ODE script for analysis of RC Capacitor voltage
circuit is presented in Fig. 30.
10
10
6
8
4
Voltage
6
2
4
0
0 5 10 15 20 25 30 35 40
Time
2
Fig. 31: Simulation result using MATLAB ODE function handle using
0
0 5 10 15 20 25 30 35 40
(RC5.m)
Time
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
MATLAB/Simulink Based Study of 17
Different Approaches Using Mathematical Model of Differential Equations
The execution of MATLAB code 'RC6.m' to evaluate On executing the MATLAB script RC10.m, the
the solution of RC circuit using transfer function for step, results of MATLAB script are presented in Fig.35.
ramp and impulse excitation is shown in Fig.32.
Voltage versus Time for step excitation
12
Step response of series RC system symbolic solution
ode solver solution
10
Amplitude
10
5
0
0 5 10 15 20 25 30 35 40 8
Time (seconds)
Ramp response of series RC system
Voltage
400
6
Amplitude
200
4
0
0 5 10 15 20 25 30 35 40
Time (seconds)
Impulse response of series RC system 2
3
Amplitude
1 0
0 5 10 15 20 25 30 35 40
0 Time
0 5 10 15 20 25 30 35 40
Time (seconds)
Fig. 35: Simulation result comparison of symbolic dsolve solution with
Fig. 32: Simulation result of RC system using TF (RC6.m) a direct solution ODE solver (RC10.m)
The execution of MATLAB script RC7.m results into The system responses to different inputs using
the current response of RC system as presented in Fig. Simulink for first order RC circuit are presented in
33. Figure 37-46, respectively. Fig. 37-38 presents the
response of Simulink model (RCS1.mdl) for step and
4
x 10
-3
Current response of RC system ramp excitations using differential equations for chosen
Current response system and simulation parameters. After running the
3.5
model, one can visualize the output of Simulink model
3 on the scope block by double clicking, or plot the result
of simulation output by entering the plotting commands
2.5
in command window or by writing script .m file. In this
Current
0
subplot (2,1,1)
0 5 10 15 20
Time
25 30 35 40
% plot simulation time index vector versus step input
400
Voltage versus Time for ramp excitation plot(ScopeData(:,1), ScopeData(:,2),'LineWidth',1)
hold on
Voltage
200
% plot simulation time index vector versus step
0
0 5 10 15 20
Time
25 30 35 40 response
Voltage versus time for impulse excitation plot(ScopeData(:,1), ScopeData(:,3),'m.','LineWidth',1)
2
xlabel('Time');
Voltage
1
ylabel('Voltage');
0
0 5 10 15 20 25 30 35 40 title ('Voltage versus time for step excitation');
Time
legend('Step Input','Step Response')
Fig. 34: Simulation result using time domain expression of (10), (13) axis ([0 40 0 16])
and (16) respectively (RC9.m) grid on
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
18 MATLAB/Simulink Based Study of
Different Approaches Using Mathematical Model of Differential Equations
Voltage
6
axis ([0 40 0 4e-3])
grid on
4
Fig. 36: MATLAB script for response plotting using MAT file of
Simulink model (RCS1.mdl)
2
0
Voltage versus time for step excitation 0 5 10 15 20 25 30 35 40
Time
15 Step Input
Step Response Fig. 39: Measured output of Transfer Function block using (RCS2.mdl)
10
Voltage
5
On running the model RCS3.mdl using pulse
excitation, for chosen system and simulation parameters
0
results the response as depicted in Fig. 40.
0 5 10 15 20 25 30 35 40
Time Voltage versus time for pulse excitation
6
-3
x 10 Current Response of RC circuit for step excitation pulse response
4 pulse input
5
3
Current
4
2
Amplitude
1 3
0
0 5 10 15 20 25 30 35 40 2
Time
1
Fig. 37: Voltage and current across capacitor for step excitations using
Simulink model (RCS1.mdl) of DE (22)
0
0 10 20 30 40 50 60
Time
Voltage versus time for ramp excitation Fig. 40: Pulse response using customized transfer function block
600
Ramp Input (RCS3.mdl)
Ramp Response
400
Voltage
-3
x 10 Current response of RC system
200 4
Current response
3.5
0
0 5 10 15 20 25 30 35 40
Time
3
Current Response of RC circuit for ramp excitation
0.03
2.5
0.02
Current
Current
0.01
1.5
0
0 5 10 15 20 25 30 35 40 1
Time
0.5
Fig. 38: Voltage and current across the capacitor for ramp excitations
using Simulink model (RCS1.mdl) of DE (22) 0
0 5 10 15 20 25 30 35 40
Time
The result of simulation of Simulink model Fig. 41: Variation of circuit current using state space model
(RCS2.mdl) created using continuous block library is (RCS5.mdl)
presented in Fig. 39. The output of Simulink model
(RCS2.mdl) created using transfer function and DE The input and output voltage across the capacitor
(RCS1.mdl) approaches are identical. using Transfer Function approach in Simulink model
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
MATLAB/Simulink Based Study of 19
Different Approaches Using Mathematical Model of Differential Equations
RCS4.mdl is obtained on scope named 'Measured input Voltage versus time for ramp excitation
600
&output' and confirm with mathematical model as Ramp Input
Ramp Response
created using ordinary differential equations. It means, 400
Voltage
both ways of creating Simulink model are correct.
200
The dynamics of Simulink model RCS5.mdl is being
solved using the state space approaches and the value of 0
0 5 10 15 20 25 30 35 40
matrix A, B, C, D are fed directly to the state space Time
Current Response of RC circuit for ramp excitation
block. The result of simulation leading to current 0.03
Current
On running the model RCS6.mdl, the results of
0.01
simulation agree with earlier obtained results of
Simulink model as created in section 5.1 to 5.3. The 0
0 5 10 15 20 25 30 35 40
input, output voltage and current response for ramp Time
excitation leading to result of simulation using Simulink Fig. 42: Simulation result of RC circuit model created using blocks of
model RCS7.mdl created using blocks of user defined user defined function library using RCS7.mdl
function library is depicted in Fig. 42. The step response
of the model fully agrees with the result obtained earlier.
On running the model RCS8.mdl using step excitation,
for chosen system and simulation parameters results, the
voltage step, ramp, impulse response and current
response are as depicted in Fig. 43 and 44, respectively.
Fig. 43: Step, ramp and impulse response using customized S-function block (RCS8.mdl)
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
20 MATLAB/Simulink Based Study of
Different Approaches Using Mathematical Model of Differential Equations
The results of simulation of Simulink model impulse response (10), (13) and (16) are depicted in Fig.
RCS9.mdl created from time domain step, ramp and 45.
10
0
0 5 10 15 20 25 30 35 40
Time
Voltage versus time for ramp excitation
600
ramp response
400
Amplitude
200
0
0 5 10 15 20 25 30 35 40
Time
Voltage versus time for impulse excitation
2
impulse response
1.5
Amplitude
0.5
0
0 5 10 15 20 25 30 35 40
Time
Fig. 45: Simulation result using RCS9.mdl developed using (10), (13) and (16)
The Simulink model RCS9.mdl and the model created calling the model using m.file with the system and
in section 5.1, 5.2, 5.4 and 5.5 is being simulated using simulation paramaters defined in the MATLAB script.
data driven modeling by defining the system paramaters The simulation results confirm with the result of
as variables in the corrosponding blocks of Simulink Simulink model RCS1.mdl to RCS9.mdl. The Simulink
model. The system paramater variable set in the model RCS10.mdl is also simulated by running
paramater dialog box of Simulink model are either MATLAB script RC_modelcall.m as depicted in Fig. 24.
defined in the MATLAB command window or by The results of simulation script are shown in the Fig. 46.
-3
Voltage versus time for step excitation x 10 Current Response of RC circuit for step excitation
20 4
Step Input
Step Response 3.5
15 3
2.5
Voltage
Current
10 2
1.5
5 1
0.5
0 0
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40
Time Time
Voltage versus time for ramp excitation Current Response of RC circuit for ramp excitation
400 0.02
ramp Input
350 ramp Response
300 0.015
250
Voltage
Current
200 0.01
150
100 0.005
50
0 0
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40
Time Time
It is evident that same results are obtained by both It is observed that running the model with different
specifying the parameters in command window and by apporches results into same corrosponding voltage/time,
running the model from MATLAB script. current/time plot for given input signal. It is evident
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
MATLAB/Simulink Based Study of 21
Different Approaches Using Mathematical Model of Differential Equations
upon inspection that all these methods produce the same Transient analysis of first order system
result. Simulation and analysis of diverse engineering
applications (first order RC circuit) based on differential Mass spring damper system
equation, transfer function, state space representation, Response analysis of series and parallel RLC circuit
user defined function, time domain response using
Simulink model is depicted in various suggested models Automobile Suspension System
as shown in section 5. The Simulink flow diagram of
first order RC system shown in section 5 merely Second Order System Investigation
recreates the same simulation as using MATLAB script
implementation depicted in section 4. In general, many common systems are represented by
a linear differential equation of 2nd order as follows:
It is evident from these plots that the system response
to various excitation conditions shows a similar output.
d 2 y(t ) dy (t )
In case of step signal, it is observed that smaller the time
2
2 n n2 y(t ) n2 u (t ) (26)
constant of the system, the faster is its response to a step d t dt
input; or the larger is the time constant, slower is the
response. At t the output of the system equals to where the variable y(t ) and u (t ) represents the
step amplitude. In case of ramp response, as t the
output of the system also becomes infinity and error output and input of the system, respectively. n
signal becomes equals to time constant. The greater the represents the natural frequency and is the damping
time constant of the system, the greater is the error. In coefficient.
case of impulse signal, as t the output of the system
The transfer function of a general second order system
decays to zero. The larger the time constant of the
is as follows:
system, the greater will be the time required to bring the
system output to zero. Y ( s) n2
H (s) 2 (27)
The response of RC circuit using various approaches X ( s) s 2 n n2
under different input conditions seems to be very similar
and results are ideal under different excitations. The
component value can easily be changed and the circuit where Y (s) and X (s) represent the Laplace
can be re-simulated. In a similar manner, these transform of output and input and H (s) represents the
approaches may be useful in deriving a solution for
transfer function of the system.
other diverse engineering applications by describing the
behavior of various electrical, mechanical, biological, In the second order system investigation, three distinct
chemical or any other systems by the governing cases are encountered for various values of damping
equations. ratio . The different values of decide the behaviour of
the system. Any linear system can be studied under
different values of damping ratio. This factor can have
following three cases:
VIII. Scope of the work
1. > 1, the roots of the characteristic equation are real
The MATLAB script implementation and Simulink and the system corresponds to over damped system.
model presented in this study can be used in numerous
diverse engineering applications. These equations occur 2. < 1, the roots of the characteristic equation are
in numerous settings ranging from mathematics itself to complex conjugate and the system corresponds to
its applications to computing, electric circuit analysis, under damped system. The time response is damped
dynamics systems, biological fields etc. An approach sinusoid.
similar to the one presented in this work can be used to
3. = 1, the roots of the characteristic equation are real
model various engineering applications. Some of the
and repeated and the system represents critically
applications for study may include:
damped system.
Biological process modeling 4. = 0, the roots of the characteristic equation are
Bacteria growth in a jar imaginary and the system provides oscillating output.
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
22 MATLAB/Simulink Based Study of
Different Approaches Using Mathematical Model of Differential Equations
same way, we can examine the effect of varying for applications as stated above. But, in a nutshell, the
various second order systems, and system behavior can response of the first and second order systems can be
be re-simulated for all the three cases. achieved using the methodology presented here through
MATLAB and Simulink. In fact, MATLAB presents
1 several tools for modeling and simulation in circuit and
s2 +2s+1 system. These tools can be used to solve DEs arising in
Step Transfer Fcn 1
Scope such models and to visualize the input and output
1 relation. The work presented here can therefore be used
s2 +1 in MATLAB Simulink based studies for a variety of
Transfer Fcn 2 applications.
1
s2 +0.4s+1
Transfer Fcn
IX Migrating from MATLAB to Open Source
1
Packages
s2 +0.6s+1
Scope 1 The work presented here can also be implemented
1 using free and open source package Scilab and Xcos.
s2 +1.2s+1 Moreover, with some modification and moderate
Transfer Fcn 4
additional efforts, the solution of governing differential
Fig. 47: Simulink model of second order system using transfer equation model developed in Simulink can be replaced
function block given by (27) by an equivalent free open source environment Scilab
and Xcos [29].
X Conclusion
In the present study, first and second order system
equations have been modeled, simulated and analyzed
using different approaches involving MATLAB and
Simulink. Moreover, through this communication, an
attempt has also been made to demonstrate the usage of
majority of blocks of Simulink sinks and continuous
block library, and to present a brief idea about data
driven modeling.
The methodology presented here using MATLAB and
Simulink may serve as an inspiration for solving similar
Fig. 48: Simulation result of second order system for 1,0 and
1st and 2nd order ODE systems governing the behavior of
n 1 using (27) diverse engineering systems such as those arising in
many contexts including mathematics, physics,
geometry, mechanics, astronomy, mechanical, civil,
thermal, biological, population modeling and many
others too. In fact, any continuous time system that can
be modeled using differential equation, by transfer
function, or the state variable can be simulated using
MATLAB and Simulink. The process used here could
very profitably be employed in the analysis of
mechanical engineering course systems such as
automobile, ship or air plane systems; and in chemical
engineering courses in temperature control system, fluid
level systems or in modelling of a chemical reactor.
Thus, in conclusion, it can be said that with model
based design, it is feasible to bridge the gap between the
theoretical foundation and practical applications, thereby
Fig. 49: Simulation result of second order system for 0.2, 0.4 & 0.6 cultivating innovation talents and promoting
undergraduate level research. The work presented here
and n 1 using (27) prepares the students to accelerate innovation through
simulation based engineering and sciences.
Due to the limitations of the length of the paper, it is
not possible to cover other diverse engineering
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
MATLAB/Simulink Based Study of 23
Different Approaches Using Mathematical Model of Differential Equations
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24
24 MATLAB/Simulink Based Study of
Different Approaches Using Mathematical Model of Differential Equations
Authors Profiles
Dr Vijay Nehra obtained
B.Tech in Electronics and
Communication Engineering
from JMIT, Radaur
Kurukshtra University and
M.E in Electronics from
Punjab Engineering College,
Chandigarh in 2000 and 2002
respectively.
He started his career as Lecturer at Technological
Institute of Textile and Sciences, Bhiwani in 2002.
Meanwhile he enrolled for Ph.D at Maharshi Dayanand
University, Rohtak and earned his Ph.D in Electronics
and Communication Engineering in 2008. He has been
with the Chaudhary Devilal Memorial Engineering
College, Panniwala Mota and Guru Jambheshwar
University of Science and Technology, Hisar from 2006
to 2008. During his career he had taught various UG and
PG courses in Electronics Device and Circuits, Linear
Integrated Circuit, Network Theory, Signal and System,
Control System, Antenna and Wave Propagation, Digital
Signal Processing, Problem Solving Using MATLAB,
Modeling and Simulation of Dynamic System and many
more along with their labs. He has also served as Dean
and Head School of Engineering and Sciences, Bhagat
Phool Singh Mahila Vishwavidyalaya, Khanpur Kalan,
Sonipat, Haryana.
He has professional experience of 11 years in teaching,
research, curriculum planning, laboratory development,
educational administration, planning, management and
execution. His current area of interest include
engineering education teaching strategies that promote
professionalism and career development, learning style
and innovative laboratories that crosscut the curriculum.
His research papers have been published in international
and national journals of repute. He is a life member of
various professional societies such as ISTE, CSI, IETE,
Institution of Engineers, Plasma Science Society of India.
Copyright 2014 MECS I.J. Intelligent Systems and Applications, 2014, 05, 1-24