NEOM Lab Manual - Experiment 1 To 5

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 46

VIRTUAL LABORATORY MANUAL

NUMERICAL AND ENGINEERING


OPTIMIZATION METHODS (NEOM)
(MC-261)

(Part-I)

DEPARTMENT OF ELECTRICAL ENGINEERING


DELHI TECHNOLOGICAL UNIVERSITY
(Formerly Delhi College of Engineering)
BAWANA ROAD, DELHI-110042
Virtual Lab Experiments: Numerical Engineering and
Optimization Methods (Sub Code: MC-261)
1. Introduction to MATLAB programming. Solving physical problems
governed by ODE using RK2 and RK4 methods in MATLAB Platform.
(PRS)

2. Introduction to the interactive SIMULINK model and use it to solve


differential equation problems/state space variable problems. Study the
performance of armature controlled DC shunt motors using SIMULINK.
(PRS)
3. Develop equations for current flowing through RL circuits and solve using
MATLAB/ Simulink. (GK)

4. Solving root finding problems in one dimension by N-R and Regula-Falsi


methods to solve algebraic equations applicable to electrical engg.
(DIKC)

5. Develop equations for power in DC circuit and find condition of maximum


power transfer using Fibonacci and Golden section methods (Gradient
methods). (DRK)

6. Solving unconstrained optimization problems using Steepest Descent


method (PRS)

7. Solving constrained minimization/maximization problems by Interior and


Exterior Penalty function methods, and also by Lagrange’s method.
Improvising the results between the methods. (AKB)

8. Find resonance frequency of single phase AC circuit using Genetic


Algorithm Technique based MATLAB toolbox. (PDJ)

9. Solving optimization problem using Fuzzy logic/toolbox and ANN


technique. (DRK)

10. Solving an optimization problem (eco dispatch/LF studies) using PSO


technique. (AKB)
EXPERIMENT # 1

Introduction to MATLAB programming. Solving physical


problems governed by ODE using RK2 and RK4 methods in
MATLAB Platform.

1
EXPERIMENT # 1

Title: Introduction to MATLAB programming. Solving physical problems


governed by ODE by RK2 and RK4 using MATLAB programming.

1. Introduction:
MATLAB program is a high level interactive graphics oriented high level software
language widely used in engineeringdesign, modeling, simulation, R&D, etc. This
program is having numerous features like math computation, numerical analysis
,electrical circuit analysis, Algorithm development, scientific and engineering
graphics, data analysis and visualization, application development, etc . Further,
the program is having another significant interactive built-in ‘SIMULINK’
program which is operated as ‘drag and drop tool’ for the similar studies.

2. Objective:
In this experiment students will learn the art of MATLAB programming and apply
this for studies and analysis of various numerical optimization techniques Runge-
Kutta 2nd and 4th order methods.

3. Requirements of Apparatus:
(i) LAPTOP/Desktop PC
(ii) MATLAB/Simulink Program by MathWorks Inc.
In order to study and learn the MATLAB/SIMULINK program, it is to be
downloaded (whatever latest version is available) in the PC/Labtop of each
student. The memory requirement for the program may be around 15-20 GW.
Once loaded and operationalize the software, students can work on that.

4. Virtual Lab Experiment:


After the program is clicked, there will be prompt to be displayed (>>) on the
screen.As the MATLAB has various built in commands, these canbe practiced
with the help of ‘help’ command. However, it is to be noted that in MATLAB
everything is a matrix, and MATLAB stands for MATrixLABoratory After being
familiar with the commands, the RK-2 and RK-4 numerical techniques are to be
studied by developing MATLAB code successfully. However,the important
features of the MATLAB programming can be learnt by practicing the followings:

2
4.1 Typical Command window on the screen:

3
4.2 File Names:

 MATLAB command files should be named with a suffix of .m, e.g.


myfile.m
 An m-file typically contains a sequence of MATLAB commands that will be
executed in order.

 A file may contain a collection of commands & functions. To run, enter m-file,
without .m, e.g.
>> myfile

5. Some of the Basic Commands

Pause Stops the execution temporarily of m-files; resume execution after pressing
any key
Pause (n) Stops the execution temporarily of m-files for n-seconds before continuing;

Hold on
Hold off

4
‘ ‘ Arrow key : Display previous line

*
‘ ’ Wild card character: Display variables that match a pattern

;
‘ ‘Semicolon: At the end of a command provides no display of the output

‘ % ‘ Percentage : At the beginning enables to put comment ( non-executable) in the prog.

‘ : ‘ Colon : used to create vectors & matrices - for row/column vectors - to specify
sub-matrices &vectors - to specify a range of values in a variable (Loop)
perform iterations -

5.1 VARIABLES

 Symbolic variable :
To create symbolic expressions, first create symbolic variables, and then use operations on them.
The syms command is a convenient shorthand for the ‘sym’ syntax. Declare variables x, y, m as
symbolic i.e. syms x, y, m.
For example:
>>syms x y
>>E = x^2+6*x+7;
>>F = subs(E,x,y)
F=
y^2+6*y+7

 MATLAB Pre-defined Constants (built-in)

 Statement or Row vector ‘ too long to fit in one line’:


Line can be continued to the next line by typing 3 or more periods ( i.e. ‘ . ‘), then pressing <
enter>

 Commands for conversion from Polar to Cartesian coordinates and vice -


versa

5
 Arithmetic Operations:

MATLAB has two different types of arithmetic operations i.e.

(i) Matrix Arithmetic operations: defined by the rules of linear algebra.

(ii) Array Arithmetic operations: carried out element by element and can be
used with multidimensional arrays.

It is to note that the period (.) character distinguishes array operations


from Matrix operations.

 Logical operators: AND, OR, NOT

 Trigonometric functions:

 Differentiation and integration commands

 Polynomial function Commands

6
 Some Built-in Functions:

6. Flow Control Loops/ Loop Commands:


 For-End
 While-End
 If-else
 If-elseif-else-end
 Switch-case-otherwise-end

7. I/O Commands:

 ‘input’ command display text on the screen,waits for the user to enter
something from the keyboard and stores in the specified variable e.g
X=input (‘Pl enter value of x=’)
>> X=input (‘Pl enter value of x=’)
>>Pl enter value of x=

 Output commands
e,g. disp(A),disp (‘ Hallo, How are You’)
[display values or text on the window]

e.g. fprintf (format),fprintf (format,variables),


fprintf(fid,format,variables),
[ fprintf displays or prints the output data to the command window or a file]

7
 Formats for fprintf

8. Examples of Matrix Operation:

8
9.0 M-Files:

When problems become complicated and require reevaluation, entering


command at MATLAB prompt is not practical and therefore,

[ Note: Do not give script file name as a MATLAB command or function or same
variable name it computes]

 In addition, there is another function called anonymous function (discussed


later) which can be used without using a function (.m) file.

9
User Defined Function File (.m file) & Function Header

 Syntax of a function

function out1= functionname1 (inp1)


function out1= functionname2 (inp1,inp2,inp3)
function [out1,out2]= functionname3 (inp1,inp2,inp3,inp4)

[This command should be written at the beginning of the m-file and saved with a file name
same as the function name (e.g. functionname1) ;Output parameter 0 or 1, can omit [ ] ; 2
or more parameters separated by commas(,) ]

Ex-1:

10
Ex-3

Coding:1
% Find reactance of a reactor
function y = react_C (c,f)
y(1)=2*pi*f;
w=y(1);
y(2)=1/(w*c);
% main prog-1 script file
c=4;
f=50;
y=react_C(c,f)

11
Ex-4

Coding:2
%IMPEDANCE calculates Xc, Xl and Z(magnitude) and Z(angle) of the RLC
connected in %series
%IMPEDANCE(R,C,L,W) returns Xc, Xl and Z (mag) andZ(angle) at W rad/s
% function file ‘impedance.m’
function x=impedance(r,c,l,w)
if nargin<4 ;%NARGIN Number of function input arguments.
error('not enough input arguments')
% function file end
% Main Script file
x(1) = 1/(w*c);
x(2) = w*l;
Zt = r + (x(2) - x(1))*i;
x(3) = abs(Zt);
x(4)= angle(Zt);
% main script file
R=input('Enter R: ');
C=input('Enter C: ');
L=input('Enter L: ');
w=input('Enter w: ');
y=impedance(R, C, L, w);
fprintf ('\n The magnitude of the impedance at %.1f rad/s is %.3f ohm\n', w,
y(3));
fprintf ('\n The angle of the impedance at %.1f rad/s is %.3f degrees\n\n', w,
y(4));

Ex-5

Coding:3
% function without brakets- whether the give no. lies between 10 & 100 or not
function inrange
a=input(‘enter the number=\n’);
If ((a>10) & (a<100))
disp(‘The number lies betn 10 & 100’);
else
disp(‘The number does not lie betn 10 & 100’);

12
9.1 Anonymous function :

Creating simple functions without having to create m-files each time.


Anonymous function can be constructed either at the MATLAB command line
or in any m-file function or script.

Syntax: fhandle = @ (arg1,arg2) expression

The sign @is the MATLAB operator that constructs a function handle giving a
means of invoking the function. Stores the value of the handle in variable
fhandle

Ex.
Coding:
a=1.3; b=0.2; c=30;
parabola=@(x) a*x.^2+b*x+c;
fplot (parabola, [-25 25])

10. Plot Commands:

( follow any MATLAB reference Book)

13
11.0 Solving Differential Equations:
 Syntax: dsolve('eq1','eq2',...,'cond1','cond2',...,'v')

eq1, eq2,... are the differential equations wrt the independent variable ,v.
Letter ‘D’ denotes differentiation of the function ‘y’ with respect to the
independent variable (t). Dy is dy/dt, D2y is d2y /dt2 , D3y is d3y /dt3. ...Dny is dny
/dtn, indicating first ,second, third and nth derivative of the function (y) wrt the
independent variable,t.
Example:
>>dsolve(’D2y=c^2*y’,’y(0)=1’,’Dy(0)=0’)
ans = 1/2*exp(c*t)+1/2*exp(-c*t)

>>dsolve(’Dx=3*x+4*y’,’Dy=-4*x+3*y’, ’x(0)=0’,’y(0)=1’)
[x,y] =
x = exp(3*t)*sin(4*t),
y = exp(3*t)*cos(4*t)

 Solving Ordinary Differnential Equation (ODE):

14
11.1 For higher order differential equation, the equation is to be transformed
into a set of first-order equations to use ODE Solvers. For example:

15
7.0 Runge-Kutta 2 and RK4 Methods:

The diff equations to be solved in power system stability analysis are


nonlinear ordinary differential equations with known initial values:

dy/dx = f(x,y)

where y is the state vector of n dependent variables and x is the


independent variable. Our objective is to solve y as a function of x, with
initial values of y and x equal to y0andx0 respectively. There are many
algorithms to solve such engineering problems, and Runge-Kutta method is
one of them.

7.1 Pre-requisites

 Taylor Series Approximation

Taylor series approximates a differentiable function ( ) in the vicinity


of an operating point x0. Such approximation is helpful in scientific and
engineering analysis, in particular, problems involving multivariable
functions.

An infinite Taylor series expansion of ( ) around 0 is given as


(where Δ = − 0):

Note that first or second order approximation often suffice in the close neighborhood
of 0.

Taylor series expansion of a function ( , ) of two variables at a point


( 0, 0) is given as

where Δ = − 0, Δ =y−y0, and all partial derivatives are computed at the operating
point: ( 0, 0).

16
 Euler’s Method:

A numerical technique to solve ordinary differential equations of the form

dy/dx = f(x,y), y(0)=0;


Soln.: Solving y at a value of x =xr (=x0+rh) for r=1,2….
x1

y1  y0   f ( x, y )dx............(1)
x0

Assuming that f(x,y)=f(xo,yo) in x0<x<x1, this Euler’s formula can be written as


y1  y0  h  f ( x0 , y0 )...........(2)

Proceeding this way, we obtain general formula:


yn1  yn  h  f ( xn , yn ) (3), where, n  0,1, 2,.........

Modified Euler’s Method:

Instead of approximating f(x,y) by F(x0,yo), we now approximate the


integral by means of trapezoidal rule to obtain:

h
y1  y0    f ( x0 , y0 )  f ( x1 , y1 ) (4)
2

We thus obtain the iterative formula:

h
y1( n1)  y0    f ( x0 , y0 )  f ( x1 , y1( n) )  (5), where, n  0,1, 2
2

17
Backward Euler’s Method:

We start at the initial point (x0, y0). Here, the derivative is to be evaluated at
point (x + h) instead of at point h. To obtain the next point, (x1, y1), we take the
derivative at x1 (not at x0) and extrapolate it at point (x0, y0).

Hence Backward Euler’s method gives us,


y1 = y0 + hf(x1, y1).
Similarly, at (x1, y1) we have
y2 = y1 + hf(x2, y2).
In general,
y n+1 = yn + hf(x n+1, yn+1),

7.2 Runge-Kutta 2nd& Runge-Kutta 4th order methods:

 Depending on the number of terms effectively retained in the Taylor series, we


have
R-K metods of different orders.

 Euler’s method may be called as Runge-Kutta 1st order method

7.2.1 Runge-Kutta 2nd Order Method

If we substitute y1  y0  h  f ( x0 , y0 ) on the right side of equ (4) and we obtain,


h
y1  y0    f0  f ( x0  h, y0  h  f 0 ) (6), where, f 0  f ( x0 , y0 )
2

Now set,
k1  h  f 0
and , k2  h  f ( x0  h, y0  k1 )
The equ (6) becomes,

1
y1  y0  k1  k2  (7)
2

This is the 2nd order Runge-Kutta formula. The error inthis formula can be
shown to be of order of h3 by expanding both sides by Taylors’s series.
18
7.2.2 Runge-Kutta 4thOrder Method

In each step the derivative is evaluated 4-times. Once at the initial point, twice at
trial midpoints, and once at a trial endpoint. From these derivatives the final
function value (shown as a filled dot).

The formula giving the value of y is

1
y1  y0  (k1  2  k2  2  k3  k4 ) (10)
6

Where,
k1  h  f ( x0 , y0 )
1 1
k2  h  f ( x0   h, y0   k1 )
2 2
1 1
k3  h  f ( x0  h, y0   k2 ) (11)
2 2
k4  h  f ( x0  h, y0  k3 )

These k1 , k2 , k3 , k4 are defined as,


k1= (slope at the beginning of step size)* h
k2= (first approximation to slope at midstep) * h
k3= (second approximation to slope at midstep) * h
k4= (slop at the end of step) * h
1
The incremental value, ( y1  y0 )  (k1  2  k2  2  k3  k4 ) weighted average of
6
estimates based on slopes at the beginning, midpoint and end of the time step.
In general terms,
1
yn1  yn  (k1  2  k2  2  k3  k4 ) (12)
6
where, k1= f (xn, yn) * h and so on for k2,k3 & k4.

19
7.3 Example of Runge-Kutta Method

Solve : y’=f(t,y)=y−t2+1
y(0) = 0.5
for0 ≤ t ≤ 2 and h=0.5
Exact solution for the problem is y = t2 + 2t + 1 –½(et)

7.3.1 RK2 Method:


Step size h = 0.5. For t = 0 to t = 1, steps: t0 = 0, t1 = 0.5, t2 = 1, t3 = 1.5, t4 = 2.
Step 0: t0 = 0, y0 = 0.5
Step 1 t1 = 0.5

k1 = hf (t0, y0) = 0.5f (0, 0.5) = 0.75


k2 = hf (t0 + h, y0 + k1) = 0.5f (0.5, 1.25) = 1.0
y1=y0+(k1+k2)/2=1.375 (RK2)
Step 2 t2 = 1

k1 = hf(t1, y1) = 0.5f(0.5, 1.375) = 1.0625


k2 = hf (t1 + h, y1 + k1) = 0.5f (1, 2.4375) = 1.21875
y2=y1+(k1+k2)/2=2.515625 (RK2)
Step 3: t3 = 1.5

y3=y2+(k1+k2)/2

Step 4: t4 = 2.0

y4=y3+(k1+k2)/2

7.3.2 RK4 Method :

Step 0 t0 = 0, y0 = 0.5.
Step 1 t1 = 0.5
k1 = hf (t0, y0) = 0.5f (0, 0.5) = 0.75
k2 = hf (t0 + h/2, y0 + k1/2) = 0.5f (0.25, 0.875) = 0.90625
k3 = hf (t0 + h/2, y0 + k2/2) = 0.5f (0.25, 0.95312) = 0.94531
k4 = hf (t0 + h, y0 + k3) = 0.5f (0.5, 1.44531) = 1.09765
y1 = y0 + (k1 + 2k2 + 2k3 + k4)/6 = 1.42513

Step 2 t2 = 1
k1 = hf (t1, y1) = 0.5f (0.5, 1.42513) = 1.08756
k2 = hf (t1 + h/2, y1 + k1/2) = 0.5f (0.75, 1.96891) = 1.20320
k3 = hf (t1 + h/2, y1 + k2/2) = 0.5f (0.75, 2.026733) = 1.23211

20
k4 = hf (t1 + h, y1 + K3) = 0.5f (1, 2.65724) = 1.32862
y2 = y1 + (k1 + 2k2 + 2k3 + k4)/6 = 2.63960

Step 3: t3 = 1.5
k1 = hf(t2, y2)= 0.5f(1, 2.63960) = 1.31980
k2 = hf (t2 + h/2, y2 + k1/2) = 0.5f (1.25, 3.29950) = 1.36850
k3 = hf (t2 + h/2, y2 + k2/2) = 0.5f (1.25, 3.32385) = 1.38067
k4 = hf (t2 + h, y2 + K3) = 0.5f (1.5, 4.02027) = 1.38513
y3 = y2 + (k1 + 2k2 + 2k3 + k4)/6 = 4.00681

Step 4: t4 = 2
k1 = hf (t3, y3) = 0.5f (1.5, 4.00681) = 1.37840
k2 = hf (t3 + h/2, y3 + k1/2) = 0.5f (1.75, 4.69602) = 1.31676
k3 = hf (t3 + h/2, y3 + k2/2) = 0.5f (1.75, 4.66519) = 1.30134
k4 = hf (t3 + h, y3 + K3) = 0.5f (2, 5.30816) = 1.15408
y4 = y3 + (k1 + 2k2 + 2k3 + k4)/6 = 5.30160

Error in respect of the exact or true solution:

ti (Numerical solution - Exact solution)

0.0 0
0.5 0.000509
1.0 0.001256
1.5 0.002336
2.0 0.003866

9. Observations
Plot the characteristics of RK2, RK4 results and True solution on the same plot.
Also plot the error curve in RK2 method iro true solution and error curve in
RK4 method iro true solution on the same plot. Give comments on the
performance of RK2 and RK4 methods.

10. Appendix :

Coding:
% Runge Kutta 4 Solution
%Rungekutta-4 soln for y’=y-t.^2+1
%function file 'f'
function f=f(t,y)
f=y-t.^2+1;
0<=t<=2,x(0)=0.5
x_true=t.^2+2*t+1.0-0.5*exp(t)% True solution
%function file 'f' ends

21
%Main file
clc
h=0.25; % step size
t(1)=0;% zero time
x(1)=0.5;% initial condition
y_true=zeros(1,8)
for i=1:8
k1=h*f(t(i),x(i));
k2=h*f(t(i)+h/2,x(i)+k1/2);
k3=h*f(t(i)+h/2,x(i)+k2/2);
k4=h*f(t(i)+h,x(i)+k3);
x(i+1)=x(i)+(k1+2*k2+2*k3+k4)/6;
t(i+1)=t(i)+h;
y_true=t.^2+2*t+1.0-0.5*exp(t)
end
%t=[0:h:2]
%y_true=t.^2+2*t+1.0-0.5*exp(t) % Solve & plot by dsolve also
plot(t,x,'k-',t,y_true,'m+')
xlabel('t')
ylabel('x')
legend('Runge Kutta 4th Order:TrueSoln vs. RK soln.')
%main file end

22
EXPERIMENT # 2

Title: Introduction to the interactive SIMULINK model and use it to solve


differential equation problems/state space variable problems. Study the
performance of armature controlled DC shunt motors using SIMULINK.

1. Introduction:

Simulink (Simulation and Link) is an extension of MATLAB by Mathworks Inc. It


works with MATLAB to offer modeling, simulation, and analysis of dynamical systems
under a graphical user interface (GUI) environment. While the MATLAB program is
downloaded, or loaded it from any pen drive, the SIMULINK program is inherently
getting loaded. Simulink is extensively used in electrical engineering design, project
modeling & simulation, R&D, solving differential equations, numerical and
engineering optimization analysis, etc.

Although some previous knowledge of MATLAB would be helpful, it is not absolutely


necessary. However, Simulink models could be also supplemented with MATLAB
functions, commands, and statements. Like MATLAB, Simulink can be used with both
linear and nonlinear systems, which can be modeled in continuous time and sample
time.

Simulink includes a comprehensive block library of toolboxes for both linear and
nonlinear analyses. As Simulink is an integral part of MATLAB, it is easy to switch
back and forth during the analysis process. It is required to explore or browse the
organisation of the toolboxes and scan their contents according to their categories.

2. Objective:

This experiment is aimed of learning the art of developing Simulink models for
electrical engineering applications. Students are to learn the simulation procedures
using Simulink tool boxes and to apply for electrical circuit simulation and armature
controlled DC motor. The typical Simulink models as illustrated in this experiment
should be tested and develop a new model of an electrical circuit.

3. Requirements of Apparatus:
(i) LAPTOP/Desktop PC
(ii) MATLAB/Simulink Program by MathWorks Inc.
In order to study and learn the Simulink program, it is to be downloaded (whatever latest
version is available) in the PC/Labtop of each student. Once loaded and operationalize
the software, students can work on the Simulink applications.

4. Virtual Lab Experiment:

Simulink includes a comprehensive block library of toolboxes for both linear and
nonlinear analyses. As Simulink is an integral part of MATLAB, it is easy to switch
back and forth during the analysis process. It is required to explore or browse the
organisation of the toolboxes and scan their contents according to their categories. The
construction of a model is simplified with click-and-drag mouse operations.
4.1 Getting Started

While MATLAB program is loaded, it displays the following menu with prompt (⪢)
sign in the command screen and type simulink and enter as given below:

>> simulink

Alternately, you may click on the ‘Simulink’ icon


located on the toolbar:

4.2 Simulink toolboxes

The various Simulink toolboxes can be explored through Library Browser (clicked multi-
coloured red-blue box of four squares as appeared in the menu bar). The Simulink
libraries will be available and cann scan their contents according to their categories.
For example, while browsing the machine (highlighted below on the LHS) tool boxes,
various machine models will be available as shown below. Similarly, other categories
of elementary models can be explored through ‘Simscape/Power Systems/Power
System components/.
4.3 Simulink file name

All Simulink model file will have an extension ".mdl" similar to how MATLAB recognizes
files with the extension .m as an MFile.

4.4 Modeling by SIMULINK

Simulink opens with the Library Browser. you will find several toolboxes categorized
on the left side of window pane shown above. Some general blocks used for
mathematical modelling.

4.4.1 Mathematical modelling

In Simulink, it is very straightforward to make a mathematical model representing


a physical system. A variety of blocks are available to the user in the librarary for
representing various phenomena and models. Mathematical models are usually
composed of relationships and variables. Relationships can be described by
operators, such as algebraic operators, functions, state vectors, diferential
operators, etc.

4.4.2 Physical modelling

Physical modeling is a way of modelling real physical components. ‘Simscape’


enables us to rapidly create models of physical systems. With Simscape, we build
physical component models based on physical connections that directly integrate
with block diagrams and other modeling elements. Some of these physical elements
are synchronous machine, asynchronous machine, motor, pumps, op-amps, etc.
Simulink uses block diagram approach, and the signal flow is unidirection. Simscape
uses physical modeling approach, and the signal flow is bi-directional between
blocks.

4.5 Do your own Simulink model

To build your model, browse the respective components and add them (blocks) to
your model window. To move the blocks around, simply click on it and drag it to a
desired location. Add a Scope from Sinks library, an Integrator block from
Continuous library, and a Mux block from Signal Routing library ,etc.

If you wish to locate a block knowing its name, you may enter the name in the
SEARCH WINDOW and Simulink will bring up the specified block. To move the
blocks around, simply click on it and drag it to a desired location. Once you have
dragged over all necessary blocks , the workspace window should consist of the all
desired components. You may remove (delete) a block by simply clicking on it once
to turn on the selected mode (with four corner boxex) and use DEL key or keys
combination CTRL-X. To display block's parameters, double click on the block.

4.5.1 Making connections

To establish connections between the blocks, move the cursor to the output port
represented by ‘>’ sign on the block. Left click while holding down the control key
and drag from source port to a destination port. The cursor will turn into a cross ‘+’
enabling to make connection between blocks.
An example is demonstrated where blocks like sine wave, integrator, mux and scope
are dragged from the library and they are connected as given below, and the output
is obtained after clicking the ‘play’ button in the menubar. Click the scope toolbox
to see the nature of the output based on the parameter set in the sine wave block
(a source block).

4.5.2 Running simulink model

You now may run the simulation of the simple system above by clicking on the play
button . Double click on the Scope block to display of the scope.
4.6 Development of Simulink model

4.6.1 Case-1: RLC circuit with unit step voltage input (u0t).

The following is an RLC-circuit to be modelled using Simulink find voltage across


the capacitor.

Rt dvc
 vcdt + C = 1- vc
L0 dt
t dv
for → R, C, L = 1 → vc = 1-  vcdt + c
0 dt

[A]
State-space vector representation:

[B]

[D]

[C]

With the above state-space equations of x1(dot) and y, where A, B, C, D are


the matrices corresponding to the RLC-circuit, the Simulink model is prepared as
shown below and the same may be developed by each student.
Voltage Profile in volts (Vc) across L and C

4.6.2 Case-2: Armature controlled DC Servo Motor.

Mathematical formulation of the Armature controlled DC Motor is illustrated


below:
PARAMETERS:
Ra – Motor armature resistance (Ohms)
La- Inductance of motor armature wdg. ( henrys)
Ia - Arm. Current (amp)
If – Field current (amps)
Ea - Applied armature voltage (volts)
Eb – Back emf (volts)
J – Equivalent moment of inertia of the motor and
load referred to the motor shaft (Kg-m2 )
𝜽 - angular displacement of motor shaft (rad)
𝝎 – angular velocity of the motor shaft (rad/sec)
Kb - motor back emf constant (v-s/rad)
Kt – motor torque constant (N-m/A)
f – equivalent damping viscous friction co-eff. Of
the mechanical system (motor &load)(N-m-s)

di
The differential equation of the armature circuit (KVL): La a + iaRa + e = ea …..(1)
dt b

While the DC motor is operated in the linear range of the magnetization curve, the air
gap flux is proportional to the field current i.e.

 = Kf if ……………(2) , where Kf is a constant

The motor back emf being is proportional to speed: e = K d …… (3)


b b dt

The torque developed by the motor is proportional to the product of the armature
current and air gap flux, as given below. As the field current is constant, the torque is
proportional to the armature current.
Tm = K1ia = K1iaKf if = KT ia ….........(4) , where KT=K1Kf = a constant

The armature current produces the torque that is applied to the inertia and friction to
obtain the torque equation,

J d  + f d = Tm = K ia ……………………(5)
2
dt 2 dt t

Laplace Transform of (1),(3) and (5) become (with initial conditions being zeros),

E (s ) = K  (s )LLLLLLLLLLLLLLLLLLLLL(6)
b b
E (s ) − E (s ).
(Las + Ra )Ia (s ) = Ea (s ) − E (s )Lor ,Ia (s ) = a b LLL(7)
b (Las + Ra )
K
(Js2 + fs ) (s ) = Tm (s ) = K Ia (s )Lor ,s (s ) = t I (s ) = (s )L(8)
t (Js + f ) a

The transfer function of the system is worked out from (6), (7) & (8):

K
G(s ) =  (s ) = t LLLLL(9)
Ea (s ) s[(Ra + sLa )(Js + f ) + K K ]
t b

Transfer function block diagram

Physical System Parameters:


The physical parameters are: (J) moment of inertia of the rotor = 0.02 kg.m2, motor
viscous friction constant (f) = 0.03 N.m.s/rad, back electromotive force constant(Kb )=
0.023 V-sec/rad, motor torque constant (Kt) = 0.023 N.m/Amp, armature ckt
resistance(Ra) = 1 Ohm, armature ckt inductance (La) = 0.023 H. No load is connected
i.e. Load Torque(TL )=0. Input voltage is 12 V applied to the motor's armature, while the
output is the rotational speed of the shaft( 𝜽) or angular velocity (𝝎). The rotor and
shaft are assumed to be rigid.

Simulink Model of the armature controlled DC motor:

Output:

Torque developed by motor , armature current, angular displacement and angular velocity can be
observed by clicking the respective ‘scope’ block.

4.6.3 Case-3:
The RLC electrical circuit (refer to case-1) is to be simulated by considering the
same R,L and C parameters. With an input voltage of u= 2 sin (t+30°) -5 cos (t+60°),
note the voltage profile across the capacitor.
CONCLUSION:
Experiment No. 3
3.1 Aim of Experiment: Develop equation for current flowing through RL circuits and solve
using Matlab/Simulink.
3.2 Objective: Learning to solve the electrical circuits using both Matlab and Simulink
environment.
3.3 Prerequisites:
1. Knowledge of Circuit Theory
2. Knowledge of basic C/C++ programming
3. Knowledge of Numerical Methods
4. Knowledge of Simulink

3.4 Software Requirements:


1. MATLAB R2015B

3.5 Theory:
3.5.1 Introduction to Runge-Kutta Method:
First order differential equation:

The above equation can be solved by many methods namely Euler method, Picard method,
Taylor series method , Runge-Kutta method.
Runge Kutta method is a popular iteration method of approximating solution of ordinary
differential equations. Developed around 1900 by German mathematicians C. Runge and M.
Wilhelm Kutta. Also known as RK method is based on solution procedure of initial value
problem in which initial conditions are known.
This method has advantage over Taylor Series method that we don’t have to calculate higher
order derivatives.
The philosophy behind Runge-Kutta methods is to consider a weighted average of slopes or
approximate slopes at a number of points.
3.5.2 Working Rule:
For finding the increment k of y corresponding to an increment h of x by Runge-Kutta method
from

Calculate successively

Finally compute,

This gives the required approximate value

3.5.3 Application to RL Circuit:

Figure 1

Applying Kirchhoff Voltage Law to the above shown circuit we get,

Rearranging above we get a first order differential equation,


This equation can be solved by using Runge-Kutta method to find the value of i(t) by writing
code in Matlab m-file and results obtained can be verified using Simulink model.

3.6 Procedure:
1. Open Matlab.
2. Open a new script file.
3. Then initialize all the constants in the system.
4. Then initialize the value of step size, range of the time and also define the initial
conditions.
5. Then define the differential equation in the script either using function file or using inline
command.
6. Then define the number of iterations for which you want to solve the equation. Try to go
for large value as it will reduce error.
7. For the given number of iterations, run a For Loop, and for each iteration solve for K1,
K2, K3, K4 and K. Update the value of I correspondingly with the calculated deviation,
K.
8. Display the final value of current I obtained after the iteration as a final result.

3.7 Result:
The result of the written code can be seen in the Command Window. This result can be
verified by simulating a similar circuit in Simulink environment and viewing the result in the
scope.
EXPERIMENT-4
4.1 OBJECTIVE
Solving root finding problems in one dimension by Newton-Rampson and Regula-Falsi methods
to solve algebraic equations applicable to electrical engineering.

4.2 SOFTWARE REQUIRED


(i) MATLAB R2013a.
(ii) Windows 7/XP SP2/10.

4.3 THEORY
4.3.1 Newton-Raphson method
Newton-Raphson method, named after Isaac Newton and Joseph Raphson, is a popular iterative
method to find the root of a polynomial equation. It is also known as Newton’s method. Based
on the first few terms of Taylor’s series, Newton-Raphson method is more used when the first
derivation of the given function/equation is a large value. It is often used to improve the value of
the root obtained using other rooting finding methods in Numerical Methods.

Derivation of Newton-Raphson Method:


The theoretical and mathematical background behind Newton-Raphson method is approximation
of the given function by tangent line with the help of derivative, after choosing a guess value of
root which is reasonably close to the actual root.
The x- intercept of the tangent is calculated by using elementary algebra, and this calculated x-
intercept is typically better approximation to the root of the function. This procedure is repeated
till the root of desired accuracy is found. Lets now go through a short mathematical background
of Newton’s method. For this, consider a real value function f(x) as shown in the Fig. 4.1.

Fig. 4.1 The Newton-Raphson method illustration


Consider x1 to be the initial guess root of the function f(x) which is essentially a differential
function. Now, to derive better approximation, a tangent line is drawn as shown in the figure.
The equation of this tangent line is given by:

y = f’(x1) (x- x1) + f(x1)

where, f’(x) is the derivative of function f(x).

As shown in the Fig. 4.1, f(x2) = 0 i.e. at x = x2, y=0


Therefore, 0 = f’(x1) (x2– x1) + f(x1)
Solving, x2 = x1 – f(x1) / f’(x1)

Repeating the above process for xn and xn+1 terms of the iteration process, we get the general
iteration formula for Newton-Raphson Method as:
xn+1 = xn – f(xn)/f’(xn)

This formula is used in the program code for Newton Raphson method in MATLAB to find
new guess roots.

Steps to find root using Newton’s Method:

1. Check if the given function is differentiable or not. If the function is not differentiable,
Newton’s method cannot be applied.
2. Find the first derivative f’(x) of the given function f(x).
3. Take an initial guess root of the function, say x1.
4. Use Newton’s iteration formula to get new better approximate of the root, say x2
x2 = x1 – f(x1)/f’(x1)
5. Repeat the process for x3, x4… till the actual root of the function is obtained, fulfilling
the tolerance of error.

Newton Raphson Method Algorithm:

1. Start
2. Read x, e, n, d
*x is the initial guess
e is the absolute error i.e the desired degree of accuracy
n is for operating loop
d is for checking slope*
3. Do for i =1 to n in step of 2
4. f = f(x)
5. f1 = f'(x)
6. If ( [f1] < d), then display too small slope and goto 11.
*[ ] is used as modulus sign*
7. x1 = x – f/f1
8. If ( [(x1 – x)/x1] < e ), the display the root as x1 and goto 11.
*[ ] is used as modulus sign*
9. x = x1 and end loop
10. Display method does not converge due to oscillation.
11. Stop

4.3.2 Regula Falsi Method


Regula Falsi Method, also known as the false position method, is an iterative method of finding
the real roots of a function. This method works by substituting test values for unknown
quantities, and is the oldest approach to solve equations in mathematics, numerical methods, and
engineering.
False position method requires two initial guesses, and uses interpolation approach to find roots.
The process starts with two guess values, say a and b such that f(a) and f(b) are of opposite sign
which confirms that the root lies in the interval [a, b].

Derivation of Regula Falsi Method:


Consider a curve having function f(x) = 0 as shown in the Fig.4.2.

Fig. 4.2 The regula falsi method illustration.


It is required to locate the value of x at a point such that at that point the value of function is equal to zero
i.e. x= r and f(r) = 0; ‘r’, which implies to the root of the equation f(x) = 0.

Consider three points on abscissa a1, b1 and c1 with respective ordinates as f(a1), f(b1) and f(c1). From the
principle of similar triangle, we have:
[f(b1) – f(a1)] /[ b1 – a1] = [ f(b1) – 0 ] / [ b1 – c1]

Rearranging the terms,


c1 = b1 – f(b1)/[ {f(b1) – f(a1)}/{ b1– a1 }]
if f(c1) = 0, the iteration is stopped, and c1 = r. This is the required formula; the code for Regula Falsi
method in MATLAB will be based on these formula and stopping criteria.

Regula Falsi Method Algorithm:

1. Start
2. Read values of x0, x1 and e
*Here x0 and x1 are the two initial guesses
e is the degree of accuracy or the absolute error i.e. the stopping criteria*
3. Computer function values f(x0) and f(x1)
4. Check whether the product of f(x0) and f(x1) is negative or not.
If it is positive take another initial guesses.
If it is negative then goto step 5.
5. Determine:
x = [x0*f(x1) – x1*f(x0)] / (f(x1) – f(x0))
6. Check whether the product of f(x1) and f(x) is negative or not.
If it is negative, then assign x0 = x;
If it is positive, assign x1 = x;
7. Check whether the value of f(x) is greater than 0.00001 or not.
If yes, goto step 5.
If no, goto step 8.
*Here the value 0.00001 is the desired degree of accuracy, and hence the stopping
criteria.*
8. Display the root as x.
9. Stop

4.4 PROCEDURE
(i) Open MATLAB
(ii) Open new M-file
(iii) Type the program
(iv) Save in current directory
(v) Compile and Run the program
(vi) For the output see command window\ Figure window
Experiment 5:

Fibonacci and Golden section methods-based optimization of the given function.

Optimization is essentially about finding the best solution (minima or maxima) to a given

problem from a set of feasible solutions. Number of different methods exist in the available

literature. In this experiment we will be discussing about the Fibonacci and Golden section

methods.

Software Required: MATLAB

Fibonacci Method: The Fibonacci search is based on the sequence of Fibonacci numbers which

are defined by the following equations

=1

=1

= + ; for N = 2,3,4, 5….

Thus, the Fibonacci numbers are 1; 1; 2; 3; 5; 8; 13; 21; 34, ….

Note: Condition for applying the Fibonacci method is that the function should be unimodal

in a given interval (i.e only one maxima/minima should be there). In other words, the

function should be increasing and decreasing monotonically about the (single)

minima/maxima point in the same interval.

Procedure:

Let y=f(x) be a given function. We are considering a one variable function and a minimization

problem. Let initial interval of uncertainty is x ∈ [a, ] be given (meaning in this interval we

need to find the value of x for which the value of y is minimum). The objective is to narrow
down this interval iteration by iteration. Initially, we do not know how many iterations are

required to perform for getting the solution. But later we will understand how to deduce it

analytically. In each iteration we take two values of the x. These two values are symmetrical with

respect to the end points of the interval (of the given iteration) that is, they are equidistant from

the end points of the interval. The algorithm is to develop some way of finding these

symmetrical distances. This distance is denoted by where k denotes the iteration.

iteration: Let the is obtained as follows:

Where n denotes the total number of iterations to performed (number of function

evaluations), denotes Fibonacci number and denotes the initial interval of

uncertainty ( . Then the two new points are obtained as follows:

and

x=a

x=b
Then conduct a two-point test, that is, evaluate and . If then delete

the interval on the right side of the and if then delete the interval on the left

side of the (since the given f(x) is unimodal).

2nd iteration: Let us assume that then in this iteration new initial interval would

be . So, one of the end points is changed and the initial interval is reduced from to

x=b

To find two new points we need It is given by:

On substituting the expression for in above expression we will get

and in general

where k<=n.

and at iteration we can write


Since So, the two new points are given as:

and

The above steps are repeated till the last iteration is reached. Further note that out of the

two new points in any iteration one of the points in it will be equal to one of the points

obtained in the previous iteration. The reduction ratio (RR) is nothing but the ratio of the

initial interval of uncertainty to the achieved/desired interval, that is;

And as we know

So, Reduction ratio is given by

So, given the desired accuracy (last interval size) and the initial interval we can find RR and

will be equal to RR. From we can deduce the value of n. For example, if =20 then we

know for n=7. So, we will carry out n+1 iteration (function evaluations). At the last

iteration we hope that the two new points will converge to each other (and hence the

solution). If they do not converge then the final interval will be so small that the mid-point

of the final interval will be considered as a solution.


Example: Minimize the area of the cylindrical solar water heater storage where the area is

given by , r stands for the radius and h stands for the height. The volume

of the tank is given by . So, on substituting the value of the volume we can

write the area as The initial interval of uncertainty is given by r ∈ [0.5, ] in

meters. Let the number of experiments to be performed are n=7.

Hint: At the 7th iteration the two points converge approximately to a value equal to 0.85

Golden section Method: In the Fibonacci method the percentage of reduction in the interval

when we go from iteration to the other is not same since gives different values for different

values of k. In golden section/ratio method this percentage of reduction is fixed while moving

from one iteration to the another. That is, the new interval is given by

for k=1,2,3….n

where 0.618 or 1.618 is called as a golden number (and see . Rest all the

procedure is same as of the Fibonacci method.

You might also like