0% found this document useful (0 votes)
5 views32 pages

project-0

The document is a lab file for a course on Modeling and Simulation using MATLAB - Simulink, detailing various experiments conducted from January to May 2024. It includes a comprehensive index of experiments, such as the study of MATLAB, single-phase converters, and various circuit configurations. Each experiment outlines objectives, methodologies, and expected outcomes related to electrical engineering applications using MATLAB and Simulink.

Uploaded by

anmol.041722
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views32 pages

project-0

The document is a lab file for a course on Modeling and Simulation using MATLAB - Simulink, detailing various experiments conducted from January to May 2024. It includes a comprehensive index of experiments, such as the study of MATLAB, single-phase converters, and various circuit configurations. Each experiment outlines objectives, methodologies, and expected outcomes related to electrical engineering applications using MATLAB and Simulink.

Uploaded by

anmol.041722
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

LAB FILE

of

Modeling and Simulation using MATLAB - Simulink


(EEE665)

Electrical Engineering Department


Faculty of Engineering,
Teerthanker Mahaveer University,
Moradabad

Jan2024-May 2024

Submitted To: Submitted By : Prince


Singh
Mr. Umesh Kumar Singh (TEN2103010)
(Assistant Professor)
INDEX

S.No. Name of Experiment Pa Remarks Signatu


g re
e
N
o
.

Study of Introduction to MATLAB


1.
3
-
8
Single phase uncontrolled 9
2. converter for R and RL load with -
capacitor filter using 1
MATLAB/SIMULINK 1
Single Phase Fully Controlled
3. Converter Using R and RL Load Using 1
MATLAB/SIMULINK 2
-
1
5
Single Phase uncontrolled inverter
4. using MATLAB/SIMULINK 1
6
-
1
7
Single phase AC
5. voltage controller 1
using MATLAB/SIMULINK 8
-
2
1
Study of Basic Matrix Operations
Using MATLAB/SIMULINK
6. 2
2
-
2
3
Determination of Eigen Values and
7.
Eigen Vectors of a Square Matrix 2
Using MATLAB Software 4
-
2
5

To Solve Linear Equation Using


8.
MATLAB Software 2
6
-
2
7
Determination of Roots of a
9. Polynomial Using MATLAB 2
8

Solution of Difference Equations


10. using MATLAB Software 2
9
-
3
1

Experiment 01
Study of Introduction to MATLAB

1. Starting MATLAB
After logging into your account, you can enter MATLAB by double-clicking on the MATLAB shortcut
icon (MATLAB 7.0.4) on your Windows desktop. When you start MATLAB, a special window called the
MATLAB desktop appears. The desktop is a window that contains other windows. The major tools
within or accessible from the desktop are:

• The Command Window


• The Command History
• The Workspace
• The Current Directory
• The Help Browser
• The Start button
2. Using MATLAB as a calculator
As an example of a simple interactive calculation, just type the expression you want to evaluate. Let’s
start at the very beginning. For example, let’s suppose you want to calculate the expression, 5 * 4 + 2.
You type it at the prompt command (>>) as follows,
>> 5*4+2
ans = 22

You will have noticed that if you do not specify an output variable, MATLAB uses a default variable
ans, short for answer, to store the results of the current calculation.
Note that the variable ans is created (or overwritten, if it is already existed). To avoid this, you may
assign a value to a variable or output argument name. For example,
>> x = 5 * 4 + 2
x = 22

3. Creating simple plots


The basic MATLAB graphing procedure, there are many ways to create a plot graph.
for example - 1,
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)
For example – 2,

Define Y as the 4-by-4 matrix returned by the magic function,


Y = magic(4)

Y = 4×4

16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1

Create a 2-D line plot of Y. MATLAB® plots each matrix column as a separate line.

figure
plot(Y)
4. Matrix generation
A vector is a special case of a matrix. The purpose of this section is to show how to create
vectors and matrices in MATLAB. As discussed earlier, an array of dimension 1 ×n is called
a row vector, whereas an array of dimension m × 1 is called a column vector. The
elements of vectors in MATLAB are enclosed by square brackets and are separated by
spaces or by commas. For example, to enter a row vector, v, type
>> v = [2 3 8 7]
v=
2 3 8 7

Column vectors are created in a similar way, however, semicolon (;) must separate the components
of a column vector,
>> v=[2 3 1 5; 1 5 6 2; 8 1 9 4]
v=
2 3 1 5
1 5 6 2
8 1 9 4
On the other hand, a row vector is converted to a column vector using the transpose
operator.
The transpose operation is denoted by an apostrophe or a single quote (’).
>> w = v’
w=

2 1 8
3 5 1
1 6 9
5 2 4

Thus, v(1) is the first element of vector v, v(2) its second element, and so forth.
Furthermore, to access blocks of elements, we use MATLAB’s colon notation (:). For example,
to access the first three elements of v, we write,
>> v(1:3)
ans =
2 1 8

Prince Singh - (TEN2103010)


Page 8
Or, all elements from the third through the last elements,
>> v(3,end)
ans =
4

where end signifies the last element in the vector. If v is a vector, writing
>> v(:)
produces a column vector, whereas writing
>> v(1:end)
produces a row vector.

Entering a matrix
To enter a matrix A, such as,
A=
9 2 6
4 5 6
7 3 1
type,
>> A = [9 2 6; 4 5 6; 7 3 1]

Note that the use of semicolons (;) here is different from their use mentioned earlier to
suppress output or to write multiple commands in a single line.

Prince Singh - (TEN2103010)


Page 9
Matrix functions

5. Introduction to programming in MATLAB


Commands with MATLAB is:
1. to create a file with a list of commands,
2. save the file, and
3. run the file.

6. Input to a script file


When a script file is executed, the variables that are used in the calculations within the file
must have assigned values. The assignment of a value to a variable can be done in three
ways.
1. The variable is defined in the script file.
2. The variable is defined in the command prompt.
3. The variable is entered when the script is executed.
% This script file calculates the average of points
% scored in three games.
% The point from each game are assigned to a variable
% by using the ‘input’ command.
game1 = input(’Enter the points scored in the first game ’);
game2 = input(’Enter the points scored in the second game ’);
game3 = input(’Enter the points scored in the third game ’);
average = (game1+game2+game3)/3

7. Output commands

Prince Singh - (TEN2103010) Page


10
Experiment-02
Single phase uncontrolled converter for R and RL load with capacitor filter using
MATLAB/SIMULINK.

A diode rectifier or uncontrolled rectifier is the converter circuit that converts ac signal into (an
alternating signal) dc signal (unidirectional signal). Uncontrolled rectifier circuits use diodes to
convert ac power to dc power and are divided into two types, single-phase and three-phase.
Again singe-phase uncontrolled rectifiers are divided into two types, they are,

1. Half-wave uncontrolled rectifier


2. Full-wave uncontrolled rectifier
i. Center tapped rectifier
ii. Bridge rectifier

Single Phase Full Wave Bridge Rectifier with R-Load :


The below figure presents the circuit connection of a single-phase full-wave bridge rectifier loaded
with a resistive load. A full-wave bridge rectifier uses four diodes connected in a close-loop
configuration which converts alternating current into direct current. The ac input to the
uncontrolled full wave rectifier is given through a transformer.

SINGLE PHASE FULL WAVE BRIDGE RECTIFIER WITH R-LOAD

When the ac supply source to the rectifier is turned ON, the positive half cycle of ac input starts.
During the positive half cycle of ac input, point A in the above circuit is made positive with respect to
point B. Due to this, diodes D1 and D2 are forward biased (since their anode terminals are connected
to positive with respect to the cathode), and diodes D3 and D4 are reverse biased (since their anode
terminals are connected to negative with respect to the cathode).

Prince Singh - (TEN2103010) Page


11
Thus diodes D1 and D2 act as the closed switch and diodes D3 and D4 act as the open switch.
Therefore, the current starts flowing from point A, through diode D1, the load resistance R, and
diode D2 to point B as shown below in figure A. The load current will continue to flow through D1
and D2 until the positive half-cycle ends.

The below shows the waveforms for output voltage Vo, output current Io, and the voltage drop
across diodes.

WAVEFORMS FOR OUTPUT VOLTAGE Vo, OUTPUT CURRENT Io


The average value of the load voltage Vdc can be calculated as follows,

Idc =2Vm/πR

The output dc power is given by,

Pdc = VdcIdc = 4Vm2/π2R

Prince Singh - (TEN2103010) Page


12
Single Phase Full Wave Bridge Rectifier with RL-Load:

In the above circuit, we have seen the full wave bridge rectifier with a resistive load where the
output current and voltage will be in phase. However, in practice loads are not purely resistive but
contain inductance in combination with the resistance. Let us see the circuit operation of an
uncontrolled full wave bridge rectifier with RL-load.

Waveforms For Single-Phase Full-Wave Uncontrolled Rectifier


with RL-Load

The value of average output voltage and output current with RL load is given by,

Prince Singh - (TEN2103010) Page


13
Experiment- 03

Single Phase Fully controlled converter using R and RL load


using MATLAB/SIMULINK.

A single phase bridge converter needs 4 thyristors. This configuration leads to two quadrant
operation. Such a converter is called the two-quadrant converter or fully controlled converter.
Many times the bridge circuit is modified by replacing two thyristors by two diodes. This
configuration leads to one quadrant operation (operation is restricted to first quadrant). Such a
converter is called the one-quadrant converter or a semi converter.

The load on the converter may be purely resistive, inductive (R-L) load or R-L-E load. An R-L-E load
consists of resistance, inductance and motor (E stands for back emf of motor). The load may also
have a battery (emf E) instead of motor.

1. With Resistive Load: A fully controlled full-wave bridge rectifier is shown in Fig. All the four
devices used in the circuit are thyristors TH 1-TH4 for control of output power. In this circuit,
diagonally opposite pair of thyristors are made to conduct, and are commutated,
simultaneously. During the first positive half cycle, thyristors TH 1 and TH3 are forward
biased and if they are triggered simultaneously, the current flows through the load via
thyristor TH1- load-TH3-source. Thus, during positive half cycle, thyristors TH 1 and TH3 are
conducting. During the negative half cycle of the ac input, thyristors TH 2 and TH4 are
forward biased and if they are triggered simultaneously, the current flows through the load
via thyristor TH2- load-TH4-source. Thyristors TH1, TH3 and TH2, TH4 are triggered at the
same firing angle α in each positive and negative half cycles of the supply voltage
respectively. When the supply voltage falls to zero, the current also becomes zero. Thus
thyristors TH1, TH3 in positive half cycle and TH 2 and TH4 in negative half cycle turn off by
natural commutation. The related voltage and current waveforms for this circuit are
depicted in Fig. below.

Prince Singh - (TEN2103010) Page


14
2. With RL Load: Figure below shows a single phase fully controlled bridge rectifier (or full
converter) with R-L load. The fully controlled bridge rectifier provides two pulses in each cycle as in
case of mid- point full-wave converter. The operating principle and waveforms of this circuit are
similar to those obtained for mid-point full-wave converter. Firing angles for both the thyristor
pairs are assumed to be equal. A large value of L will result in a continuous steady current in the
load. A small value of L will produce a discontinuous load current for large firing angles. The
waveforms with two different firing angles are depicted in Fig. 27.16.

The voltage waveform at the dc terminals comprises a steady dc component superimposed with
an ac ripple component, having a fundamental frequency equal to twice that of ac supply.

Prince Singh - (TEN2103010) Page


15
VOLTAGE AND CURRENT OUTPUT WAVEFORMS

As illustrated in Fig. above, at firing angle α = 60°, thyristors TH 1 and TH3 are triggered. Supply voltage
from this instant appears across the output terminals and forces the current through the load. The
load current Idc is assumed to be constant. This current also flows through the supply and the direction
is from line to neutral, which is taken positive as depicted in Fig.(a) along with the applied voltage. At
instant π, the supply voltage reverses but because of very large inductance L, the current keeps
flowing in the same direction at constant magnitude I dc. Thus the thyristors TH1 and TH3 remain in
conducting state and therefore, the negative supply voltage appears across the output terminals. At an
angle π + α, thyristors TH 2 and TH4 are triggered. With this, negative supply voltage reverse biases
thyristor TH1 through thyristor TH2 and thyristor TH3 through thyristor TH4 of commutating thyristor
TH1 and TH3. The current continues flowing in every half cycle and output voltage is obtained as
depicted in the figure. As illustrated the current is positive when TH 1 and TH3 are conducting and
negative when TH2 and TH4 are conducting.

The average output dc voltage is given by

The average value of output dc voltage can be varied, by varying firing angle α, continuously from
positive maximum to negative maximum, assuming continuous current flow at the dc terminals.
Because the average dc voltage is reversible even though the current flow in the load is
unidirectional, the power flow in the convener can be in either direction. Thus full converter
provides two modes of operation.

Prince Singh - (TEN2103010) Page


16
(a) Rectification Mode: For firing angle α less than 90°, the input ac supply is rectified by the
circuit. The average value of voltage at the dc terminals is positive in the range from 0° to 90°, as
illustrated in Fig. 27.16 (c) . In this mode, the power is transferred from the source to the load.

(b) Inversion Mode: For firing angle between 90° and 180°, the load voltage is negative which means
that the power is supplied from the load to the source. Waveforms for α = 135° are shown in Fig.
27.16 (b). Such an operation is used in the regenerative braking mode of dc drives and in high
voltage direct current (HVDC) transmission.

Prince Singh - (TEN2103010) Page


17
Experiment-04

Single Phase uncontrolled inverter using MATLAB/SIMULINK

A single phase voltage source inverter inverts the DC voltage into square-wave ac or sine-wave ac
voltages. Currently, there are two types of voltage inverters on the market: the first is a full-bridge
voltage source inverter, which consists of four switches, IGBTs, or MOSFETs, and the second is a
single-phase voltage source inverter, which consists of two switches, IGBTs, or MOSFETs. These
voltage source inverter applications include single phase UPS and switching power supplies. These
have been mostly used in high-power static power topologies.

Simulink Model of Single Phase Voltage Source


Inverter
In this article, we will explain how we can make a single phase voltage source inverter as well as
how we choose the components with the help of the MATLAB Simulink model. First, we will
explain how we can make a new model in MATLAB. To make a new model, just open MATLAB and
click on the Simulink library. After clicking on Simulink Library, a new page will open with the name
“Simulink Library Browser”.

Simulink Model
Similarly, we search and drag all the other component blocks, such as the pulse generator, logic
gate, capacitor, resistor, etc. Then we join the circuit according to our requirements. Now our
single phase voltage source inverter is complete with the help of the MATLAB Simulink library. The
Simulink model circuit can be seen in the figure below.

Prince Singh - (TEN2103010) Page


18
This single-phase voltage source inverter Simulink model uses two IGBTs, two 50 μF capacitors, a
100 V DC voltage supply, and one NOT Gate logic operator. We also had to attach a one-ohm
resistor between two capacitors because MATLAB Simulink did not allow us to simulate this circuit
without this resistor, but in hardware there is no need to join this resistor. Lastly, we use a 10 Ω
resistor as an output load. Now, we run or simulate this circuit at a 50% duty cycle. The duty cycle
is set by double-clicking on the pulse generator and then according to the figure below.

Simulation
Because both IGBT switches should not be ON at the same time, one gate pulse directly connects
with one IGBT switch, and the other gate pulse is connecting with the other IGBT switch after NOT
Gate. In other words, this circuit works through complementary switching. When we simulate this
circuit at 50% duty cycle, then the output voltage would be half of the supply voltage, which
means
it would be 50 volts, as shown in the figure below.

Prince Singh - (TEN2103010) Page


19
Experiment 05
Single phase AC voltage controller using MATLAB/SIMULINK

The ac voltage controller also called as AC Regulator is a static power electronic circuit that converts
fixed ac to variable ac. It accomplishes this task without a change in frequency. It finds application in
heating, lighting circuits, speed control of ac machines, fan regulators, etc, similar to the applications
of an autotransformer.

The circuit of the ac voltage controller is based on either thyristors, TRIACs, SCRs, or IGBTs, which
gives a variable ac at the output when their triggering angle is adjusted or varied. The output voltage
is either increased, decreased, or kept constant by varying the RMS value of input fixed alternating
voltage.

Single Phase Half Wave AC Voltage Controller :


The full-wave or bidirectional ac voltage controller uses two thyristors instead of one thyristors and
diode. The two thyristors are connected in anti-parallel. Let see the working of full-wave ac voltage
controller with resistive (R) load and resistive-inductive (RL) load.

During the positive half cycle of the source voltage VS, SCR T1 is forward biased and SCR T2 is reverse
biased. No conduction of load current takes place until thyristor T1 is triggered at some firing angle α.
So, the entire supply voltage VS appears across thyristor T1 with the same polarity and across T2 with
the reversed polarity. As soon as the thyristor T1 is triggered at the instant ωt = α, T1starts.
Conducting and the entire supply voltage VS,except the drop across T1,appears across the load
resistance.

Prince Singh - (TEN2103010) Page


20
Thereafter thyristor T2 will be forward biased and T1 will be reverse biased and of course, there will
be no conduction until T2 is triggered i.e., until (π + α).
Single-phase AC Voltage Controller Using R-Load:
The above shows the waveforms for source voltage, gating signals, output voltage, output current and
the voltage across the SCRs. At ωt=π, the load voltage, the load current falls to zero and therefore
T1 stops conducting. Thereafter thyristor T2 will be forward biased and T1 will be reverse biased and
of course, there will be no conduction until T2 is triggered i.e., until (π + α).

As long as thyristor T1 in ON state, i.e., from α<ωt<π, voltage across T2 will be VT2 = –VT1 = (ON –
state voltage drop of T1). At ωt=(π+α), thyristor T2 is triggered and it starts conducting. Except for
the small voltage drop across T2,the entire supply voltage appears across the load resistance and
the load current flows. As long as T2 is in ON state, i.e., from(π + α) < ωt < 2π, voltage across T1 will
be VT1 = -VT2= -(ON-state voltage drop of T2).
This process goes on and continues for every cycle as shown in the waveform. For resistance load,
the source current waveform will follow the source voltage waveform i.e., both the voltage and
current of the source will be in phase with each other.

Prince Singh - (TEN2103010) Page


21
Single Phase Full Wave AC Voltage Controller with RL Load:
The below shows the single-phase ac voltage controller circuit with resistive and inductive load

Prince Singh - (TEN2103010) Page


22
Single Phase AC Voltage Controller Operation When α ≤ Φ:

Consider α = Φ (load phase angle) i.e., the ac voltage regulator is operating under steady-state conditions. The
conduction period of SCR T2 is from zero to Φ and from Φ to (π + Φ) SCR T1 will conduct and again from (π + Φ)to
(2π + Φ)SCR T2 will conduct as shown in the waveform below.

Wave forms for Single Phase AC Voltage controller with RL Load


Thus, from Φ to (π + Φ), T1 will conduct. If T2 is triggered at a firing angle (π + α) < (π + Φ), then T2 will
remain OFF because T1 is conducting a current iT1 and the voltage drop across T1 will make SCR T2
reverse bias. At ωt = (π+Φ), T2 will get turned ON since the voltage drop and conduction current in T 1 at
this instant becomes zero. Thus, SCR T2 will conduct from (π+Φ) to (2π+Φ).
At the instant ωt = π, the load and source voltages become zero but, the current possesses some value
due to the presence of inductance at the load side. So, thyristor T1 continues to conduct until the current
flowing through it becomes zero. The angle at which thyristor current becomes zero is known as extinction
angle β. So, output voltage and current are equal to source voltage and current from α to β respectively.
From angle β to (π + α), the value of load voltage and load current will be zero. At the instant ωt =(π + α),
thyristor T2 is triggered and it starts conducting. So, the load current which is the same as current iT2
through T2 will flow in the reverse direction. At the end of the first cycle i.e., at the instant ωt=2π source
voltage VS and load voltage VO becomes zero but the current doesn’t become zero. At the instant ωt=
(π+α+γ) where, ωt=γ

Prince Singh - (TEN2103010) Page


23
For
High Inductance Value:
It is known as conduction angle, the thyristor current i T2 becomes zero. This turns OFF thyristor T 2
and it get reverse biased as shown in the waveform.

The RMS value of output voltage and current with RL load is given by:

Prince Singh - (TEN2103010) Page


24
Experiment 06
Study of basic matrix operations using MATLAB/SIMULINK

The basic operations on Matrix is as follow:

1. Write a Matrix in Matlab


Matrix = [9 2 6; 4 5 6; 7 3 1]

Matrix =
9 2 6
4 5 6
7 3 1

2. Find the size of a Matrix


The size of a Matrix is its number of rows and columns. To find the size of a Matrix, use the
following code

Size(Matrix)
Ans =
3 3

3. Add A and C using the following code


This is the type of code that will be executed in matlab.
x = [9 2 6]
v = [1 2 3]
v+x
ans =
10 4 9

4. Divide Matrices element by element


To divide two Matrices element by element use the following

V/X

Prince Singh - (TEN2103010) Page


25
5. Find the inverse of a Matrix
To find the inverse of a Matrix in Matlab, use the following code
Inv(V)

6. Find the determinant of a Matrix


To find the determinant of a Matrix in Matlab, use the following code

Det(V)

7. Define a Matrix with Random elements


To create a Matrix with Random element in Matlab use this code,
While 3 and 2 are the size of the matrix.

Rand(3,2)
8. Find the diagonal of a Matrix
To find the main diagonal of V, use

Diag(V)

9. Compute the Transpose of a Matrix


To find the transpose of a Matrix, use the following

Transpose(C) Or C’

C=
5 1 3
6 5 2
9 4 7

ans =
5 6 9
1 5 4
3 2 7

Prince Singh - (TEN2103010) Page


26
Experiment 07
Determination of Eigen values and Eigen vectors of a square matrix using MATLAB
software
Eigen values and Eigen vectors are properties of a square matrix.
Let is an N*N matrix, X be a vector of size N*1 and be a scalar.
Then the values X, satisfying the equation are eigenvectors and eigenvalues of matrix A
respectively.
o A matrix of size N*N possess N eigen values
o Every eigen value corresponds to an eigenvector.
Matlab allows the users to find eigen values and eigenvectors of matrix using eig()
method. Different syntaxes of eig() method are:
Let
A = gallery("lehmer",4)
A = 4×4

1.0000 0.5000 0.3333 0.2500


0.5000 1.0000 0.6667 0.5000
0.3333 0.6667 1.0000 0.7500
0.2500 0.5000 0.7500 1.0000

Calculate the eigenvalues of A. The result is a column vector.


e = eig(A)
e = 4×1

0.2078
0.4078
0.8482
2.5362

Output :
Alternatively, use outputForm to return the eigenvalues in a diagonal matrix.

D = eig(A,"matrix")
D = 4×4

0.2078 0 0 0
0 0.4078 0 0
0 0 0.8482 0
0 0 0 2.5362

o It returns the diagonal matrix D having diagonals as eigen values.


o It also returns the matrix of right vectors as V.
o Normal eigenvectors are termed as right eigenvectors.
o V is a collection of N eigenvectors of each N*1 size(A is N*N size) that satisfies A*V
= V*D

Prince Singh - (TEN2103010) Page


27
Experiment 08
To solve linear equation using MATLAB Software

We can use the Matlab built-in function solve() to solve the system of linear equations in Matlab.
First of all, we can define the variables using the syms variable. After that, we can write the
equations in Matlab. After that, we need to use the function solve() to solve the equations. For
example, let’s define some equations in Matlab and find their solution using the solve() function.
See the code below.

yms x y z
eqn1 = 2*x + y + z == 2;
eqn2 = -x + y - z == 3;
eqn3 = x + 2*y + 3*z == -10;
sol = solve([eqn1, eqn2, eqn3], [x, y, z]);
xSol = sol.x;
ySol = sol.y;
zSol = sol.z;

Output:

(x = 3)

(y = 1)

(z = -5)

Prince Singh - (TEN2103010) Page


28
Experiment 09
Determination of roots of a polynomial using MATLAB

Syntax r = roots(p) returns the roots of the polynomial represented by p as a column vector. Input
p is a vector containing n+1 polynomial coefficients, starting with the coefficient of xn. For
3 2
example, p = [12 34 1 1] represents the polynomial 12x - 34x + x + 1. A coefficient of 0 indicates
an intermediate power that is not present in the equation.
n
The roots function solves polynomial equations of the form p1x +...+pnx+pn+1=0. Polynomial
equations contain a single variable with nonnegative exponents.
Examples
1. Roots of Quadíatic Polynomial
Solve the equation 3x2−2x−4=0.
Cíeate a vectoí to íepíesent the polynomial, then find the íoots.
Get

p = [12 34 1 1];
r =
roots(p) r
= 2×1

2.7928
0.1942
-0.1537

Prince Singh - (TEN2103010) Page


29
Experiment 10
Solution of Difference Equations using MATLAB Software

First-Order Linear ODE


Solve this differential equation.
dy/dx=ty
First, represent by using syms to create the
symbolic function y(t). syms y(t)
Define the equation using == and represent differential using the diff function.
ode = diff(y,t) == t*y
ode(t) = diff(y(t), t) == t*y(t)

Solve the equation using dsolve.


ySol(t) =
dsolve(ode) ySol(t)
= C1*exp(t^2/2)

Solve Differential Equation with Condition


In the previous solution, the constant C1 appears because no condition was
specified. Solve the equation with the initial condition y(0) == 2. The dsolve
function finds a value of C1 that satisfies the condition.
cond = y(0) == 2;
ySol(t) =
dsolve(ode,cond)
ySol(t) =2*exp(t^2/2)
.
Non Linear Differential Equation with Initial Condition
Solve this nonlinear differential equation with an initial condition. The equation has
multiple solutions.
(dy/dx +y)2=1, y(0)=0
Syms y(t)
Ode = (diff(y,t)+y)^2 ==1;
Cond = y(0) ==0;
ysol(t) = dsolve(ode,cond)
ysol(t) = exp(-t) - 1

Prince Singh - (TEN2103010) Page


30
Second-Order ODE with Initial Conditions
Solve this second-order differential equation with two initial conditions.
d2y/dx2=cos(2x)-y
y(0)=1
y’(0)=0

Steps:-Define the equation and conditions. The second initial condition involves the first derivative
of y. Represent the derivative by creating the symbolic function Dy = diff(y) and then define
the condition using Dy(0)==0.
syms y(x)

Prince Singh - (TEN2103010) Page


31
Dy = diff(y);

ode = diff(y,x,2) ==
cos(2*x)-y; cond1 = y(0) ==
1;
cond2 = Dy(0) == 0;
Solve ode for y. Simplify the solution using the simplify function.
conds = [cond1 cond2];
ySol(x) =
dsolve(ode,conds); ySol =
simplify(ySol)
ySol(x) = 1 - (8*sin(x/2)^4)/3

Prince Singh - (TEN2103010) Page


32

You might also like