Escolar Documentos
Profissional Documentos
Cultura Documentos
GREATER NOIDA
2017-18
LAB MANUAL
DEPARTMENT OF:
LAB INCHARGE:
RAGINI MALVIYA
PC: Choose the submenu "Programs" from the "Start" menu. From the "Programs"
menu, open the "MATLAB" submenu. From the "MATLAB" submenu, choose
"MATLAB".
Note: From now on an instruction to press a certain key will be denoted by <>, e.g.,
pressing the enter key will be denoted as <enter>. Commands that should be typed at
the prompt, will be written in courier font.
The MATLAB environment (on most computer systems) consists of menus, buttons
and a writing area similar to an ordinary word processor. There are plenty of help
functions that you are encouraged to use. The writing area that you will see when you
start MATLAB, is called the command window. In this window you give the
commands to MATLAB. For example, when you want to run a program you have
written for MATLAB you start the program in the command window by typing its
name at the prompt. The command window is also useful if you just want to use
MATLAB as a scientific calculator or as a graphing tool. If you write longer
programs, you will find it more convenient to write the program code in a separate
window, and then run it in the command window.
In the command window you will see a prompt that looks like >> . You type your
commands immediately after this prompt. Once you have typed the command you
wish MATLAB to perform, press <enter>. If you want to interupt a command that
MATLAB is running, type <ctrl> + <c>.
The commands you type in the command window are stored by MATLAB and can be
viewed in the Command History window. To repeat a command you have already
used, you can simply double-click on the command in the history window, or use the
<up arrow> at the command prompt to iterate through the commands you have used
until you reach the command you desire to repeat.
at the prompt. Be careful with parantheses and don't forget to type * whenever you
multiply!
Note that MATLAB is case sensitive. This means that MATLAB knows a difference
between letters written as lower and upper case letters. For example, MATLAB will
understand sin(2) but will not understand Sin(2).
Examples
GIVEN NUMERICAL:
A= 3 2 1
0 3 4
-1 1 -1
B= 1 3 0
2 6 4
-1 0 2
Where A and B are two 3 X 3 matrix
COMMANDS:
>> A= [3 2 1; 0 3 4; -1 1 -1]
>> B= [1 3 0; 2 6 4; -1 0 2]
Sum: A+ B
Subtraction: A–B
Multiplication: A*B
Division: A/B or A\B
Inverse of A: inv(A)
RESULTS:
6 21 10
2 18 20
2 3 2
1 1 1
1 1 1
1 1 1
>> a(:, 2:3) % gives second and third column of matrix ‘a’
ans:
1 1
1 1
1 1
>> a(2:3,1:2) %gives second and third row and first and
second column of matrix ‘a’
ans:
1 1
1 1
For Determining the eigenvalues and eigenvectors in MATLAB eig function is used. For an
nxn matrix A, eig(A) returns a n x1 column vector whose elements are the eigenvalues of A. The
command in the form
[𝑉 𝐷] = 𝑒𝑖𝑔(𝐴)
Computes both the eigenvalues and eigenvectors of A. V will be a matrix whose columns are
eigenvectors of A and D will be a diagonal matrix whose entries along the diagonal are
eigenvalues of A. The ith column of V, V(:, i), is the eigenvector corresponding to the eigenvalue
D(i,i). For example:
A = [ 1 2 3; 4 5 6; 7 8 9]
>> A = [ 1 2 3; 4 5 6; 7 8 9]
>> eig(A)
>> [V D]=eig(A)
RESULT:
CONCLUSION:
EXPERIMENT NO. 2
OBJECTIVE: DETERMINATION OF ROOTS OF A POLYNOMIAL
THEORY:
POLYNOMIAL:
The coefficients are often real numbers and which is a nonnegative integer, is
the degree or order of the polynomial.
In MATLAB, Polynomials are described by using a row vector of the coefficients of the
polynomial beginning with the highest power of x and inserting zeros for “missing” terms:
f= [9 -5 3 7]
g= [6 -1 2]
ROOTS OF A POLYNOMIAL:
Roots of a polynomial
are the values of for which . For example, the roots of are -
1 and -2. There are n roots of a polynomial with degree n.
The command “roots” determines the roots of a polynomial. The usage of the function is:
r= roots (p)
Where r is a column vector with the roots and p is a row vector with the coefficients of the
polynomial.
PROGRAM:
>> p = [3 15 0 -10 0 4 0]
>> roots(p)
RESULT:
-4.8613
-0.6925 + 0.3093i
-0.6925 - 0.3093i
0.6232 + 0.2975i
0.6232 - 0.2975i
THEORY:
Curve fitting is a technique of finding an algebraic relationship that “best” (in least squares
sense) fits a given set of data. Unfortunately, there is no magical function (in MATLAB or
otherwise) that can give the relationship if we simply supply the data. We have to have an idea of
what kind of relationship might exist between the input data and the output data. However, if we
do not have the firm idea but have data that we trust, MATLAB can help us in exploring the best
possible fit.
MATLAB includes Basic Fitting in its Figure window’s Tools menu that lets us fit a
polynomial curve (upto 10th order) to the data on the fly. It also gives us options of displaying the
residual at the data points and computing the norm of the residuals. This can help in comparing
different fits and then selecting the one that best fits.
PROGRAM:
x=linspace(0,4*pi,10)
y=sin(x)
p=polyfit(x,y,7)
x1=linspace(0,4*pi)
y1=polyval(p,x1)
plot(x,y,'o')
hold on
plot(x1,y1)
hold off
OUTPUT:
RESULTS:
CONCLUSION:
EXPERIMENT NO. 4
THEORY:
The fourth-order Runge -Kutta (RK4) method having a truncation error of O(ℎ4 ) is one of the
most widely used methods for solving differential equations. Its algorithm is described below:
ℎ
𝑦𝑘+1 = 𝑦𝑘 + 6 (𝑓𝑘1 + 2𝑓𝑘2 + 2𝑓𝑘3 + 𝑓𝑘4 ) (1)
Where
𝑓𝑘1 = 𝑓(𝑡𝑘 , 𝑦𝑘 ) (2)
ℎ ℎ
𝑓𝑘2 = 𝑓( 𝑡𝑘 + 2 , 𝑦𝑘 + 𝑓𝑘1 2 ) (3)
ℎ ℎ
𝑓𝑘3 = 𝑓( 𝑡𝑘 + 2 , 𝑦𝑘 + 𝑓𝑘2 2 ) (4)
PROGRAM:
close all
clear all
x(1)=0;
y(1)=-2;
h=0.1;
for i=1:10
k1=h*(-2*x(i)-y(i));
k2=h*(-2*(x(i)+0.5*h)-(y(i)+0.5*k1));
k3=h*(-2*(x(i)+0.5*h)-(y(i)+0.5*k2));
k4=h*(-2*(x(i)+h)-(y(i)+k3));
y(i+1)=y(i)+1/6*(k1+k2+k3+k4);
x(i+1)=x(i)+h;
end
hold on
plot(x,y,'+-','color','blue')
xlabel('x-axis')
ylabel('y-axis')
legend('R-K 4th order method')
OUTPUT:
CONCLUSION:
EXPERIMENT NO. 5
OBJECTIVE: DETERMINATION OF TIME RESPONSE OF AN R-L-C CIRCUIT
GIVEN NUMERICAL
An R-L-C circuit has R = 180 ohms, C = 1/280 farads, L = 20 henries and an applied voltage E(t)
= 10 sin t. Assuming that no charge is present but an initial current of I ampere is flowing at t = 0
when the voltage is first applied, find q and i =dq/dt at any time t. The differential equation of
RLC series circuit is given by:
𝑑𝑞 𝑞
𝐿 𝑑 2 𝑞/𝑑𝑡 2 + 𝑅 + = 𝐸(𝑡)
𝑑𝑡 𝑐
PROGRAM:
syms q t
q = dsolve(‘20*D2q +180*Dq +280*q = 10*sin(t)’, ‘q(0)=0’)
simplify(q)
pretty(q)
i=diff(q)
pretty(i)
RESULTS:
q=
exp(-2*t)*C2+exp(-7*t)*(-C2+9/500)-9/500*cos(t)+13/500*sin(t)
>> pretty(q)
9 9 13
exp(-2 t) C2 + exp(-7 t) (-C2+500) - cos(t) + 500 sin(t)
500
>> i=diff(q)
i=
-2*exp(-2*t)*C2 – 7*exp(-7*t)*(-C2 +9/500)+ 9/500*sin(t)+13/500 *cos(t)
>> pretty(i)
13
-2 exp(-2t) C2-7 exp(-7 t)(-C2 +9/500)+9/500 sin(t)+ 500 cos(t)
RESULT:
CONCLUSION:
EXPERIMENT NO. 6
OBJECTIVE: STEP, RAMP AND IMPULSE RESPONSE OF TRANSFER FUNCTION
PROGRAM:
s= tf('s')
figure
subplot(311), step(G)
subplot(312), step(G/s)
subplot(313), impulse(G)
OUTPUT:
EXPERIMENT NO. 7
OBJECTIVE: GENERATION OF SINGLE AND THREE PHASE SINUSOIDAL
WAVEFORM
PROGRAM:
t=0:0.002:0.04
y=sin(2*pi*50*t)
plot(t,y)
hold on
t1=0.005:0.002:0.045
y1=sin(2*pi*50*t)
plot(t1,y1)
hold on
t2=0.01:0.002:0.05
y2=sin(2*pi*50*t)
plot(t2,y2)
grid;
xlabel('time(s)')
ylabel('amplitude')
title('Three Phase Sine Waveform')
RESULT:
CONCLUSION:
EXPERIMENT NO. 8
PROGRAM:
f=1e3;
a0=0;
Ampsin=5;
t0=0;
tf=0.01;
Ts=1e-6
v=3;
AmpPWM=1
t=t0:Ts:tf
fun= Ampsin*sin(2*pi*f*t + a0);
PWM= AmpPWM*(fun>v)
clf
plot(t,fun)
hold on
plot(t,PWM, 'r')
RESULT:
SIMULINK MODEL:
RESULT:
CONCLUSION:
EXPERIMENT NO. 9
OBJECTIVE: SINGLE LINE MODELLING OF DC MOTOR
SIMULINK MODEL:
RESULT:
CONCLUSION:
EXPERIMENT NO. 10
OBJECTIVE: SINGLE PHASE UNCONTROLLED HALF WAVE RECTIFIER USING R
AND RL LOAD
SIMULINK MODEL:
RESULT:
Single Phase Uncontrolled Half Wave Rectifier Using RL Load
RESULT:
CONCLUSION:
EXPERIMENT NO. 11
OBJECTIVE: SINGLE PHASE UNCONTROLLED FULL WAVE RECTIFIER USING R
LOAD
SIMULINK MODEL:
Single Phase Uncontrolled Full Wave Rectifier Using R Load (Bridge Type)
RESULTS:
Single Phase Uncontrolled Full Wave Rectifier Using R Load (Center Tap Transformer Type)
RESULT:
CONCLUSION:
EXPERIMENT NO. 12
OBJECTIVE: THREE PHASE UNCONTROLLED FULL WAVE RECTIFIER USING R
AND RL LOAD
SIMULINK MODEL:
RESULT:
Three Phase Uncontrolled Full Wave Rectifier Using RL Load
RESULT:
CONCLUSION: