Electrical Network Analysis (EL 228) : Laboratory Manual Fall 2021
Electrical Network Analysis (EL 228) : Laboratory Manual Fall 2021
(EL 228)
LABORATORY MANUAL
Fall 2021
LAB 01
Introduction to MATLAB
Engr. Rukhsar Ali
______________________________________
LAB ENGINEER'S SIGNATURE & DATE
Introduction
MATLAB stands for Matrix Laboratory, is numeric computation software for engineering and scientific
calculations. MATLAB is primarily a tool for matrix computations.The graphics are integrated in MATLAB.
Since MATLAB is also a programming environment, a user canextend the functional capabilities of
MATLAB by writing new modules.
MATLAB has a large collection of toolboxes in a variety of domains. Someexamples of MATLAB toolboxes
are Control System, Signal Processing, Neural Network, Image Processing and Communications System.
The toolboxes consistof functions that can be used to perform computations in a specific domain.In
laboratory we will use MATLAB as a toolfor graphical visualization and numericalsolution of basic
electrical circuits included in Circuit Network Analysis course.
When MATLAB is invoked, the Command Window will display the prompt >>. MATLAB is then ready for
entering data or executing commands. To quit MATLAB, type the command exit or quitor directly close
it. MATLAB also provides on-line help. MATLAB statements are normally of the form: variable =
expression.
Expressions typed by the user are interpreted and immediately evaluated by theMATLAB system. If a
MATLAB statement ends with a semicolon, MATLABevaluates the statement but suppresses the display
of the result.To immediately display the results enter the statement and press enter. MATLAB allows
operations involving complex numbers. Complex numbersare entered using function i or j.
Example 1.1
>> a=2+4
a=
6
Example 1.2
>> a=5;
>> b=7;
>> c=a*b
c=
35
M Files
Normally, when single line commands are entered, MATLAB processes the commands immediately and
displays the results. MATLAB is also capable of processing a sequence of commands that are stored in
files with extension ‘m’. MATLAB files with extension m are called m-files. M-files can either be script
files or function files. Both script and function files contain a sequence of commands. Script files are
especially useful for analysis and design problems that require long sequences of MATLAB commands.
Basic Commands
a) clear all
It clears all the variables or functions from Workspace. This frees up system memory.
b) close all
d) %
Graphical Commands
MATLAB also allows one to give titles to graphs, label the x- and y-axes, and add a grid to graphs. In
addition, there are commands for controlling the screen and scaling.
a) plot
It generates 2-D line Plot. There are two important variations of the plot command. plot(x)produces a
plot of the elements in the vector X as a function of the index of the elements in X. MATLAB will connect
the points by small line.
Example 1.3
Fig - 1.1
If x and y are vectors of the same length, then the command plot(x, y) plots the elements of x (x-axis)
versus the elements of y (y-axis).
Plotting functions accept string specifiers as arguments and modify the graph generated accordingly.
Three components can be specified in the string specifiers along with the plotting command. They are:
Line style, Marker symbol and Color. Details are in the following tables:
Example 1.4
Fig - 1.2
plot(x,y,'-.or') plots y versus x using a dash-dot line (-.), places circular markers (o) at the data points, and
colors both line and marker red (r). Specify the components (in any order) as a quoted string after the
data arguments.
b) axis
It freezes the axis limits.axis([xminxmaxyminymax]) sets the limits for the x- and y-axis of the current
axes.
c) title
It adds title to current figure.title(‘string’) adds the title consisting of a string at the top and in the
center of the current axes.
d) xlabel
Itlabels x-axis.xlabel(‘string’) labels the x-axis of the current axes with the string.
e) ylabel
It labels y-axis.ylabel(‘string’) labels the y-axis of the current axes with the string.
f) hold
hold function retains the current graph and adds another graph to it.
g) grid
h) legend
It places a legend on graph.legend('string1','string2',...) displays a legend in the current axes using the
specified strings to label each set of data.
Example 1.5
Capacitor voltage ‘Vc’ in series RC circuit is given by 6*(1-exp(-2*t)). Plot Vc versus time ’t’. Take t from 0
to 4 seconds.
Matlab Code
grid
Result
Example 1.6
Matlab Code
clear all
close all
clc
f=50; % Frequency definition
t=0:0.00005:0.02;% Continuous time from 0 to 0.02 with 0.000005 step
x=sin(2*pi*f*t); % Evaluating sine wave
plot(t,x)% Plotting x with respect to t
title('Sine Wave of frequency 50 Hz')
xlabel('time(sec)')
ylabel('Sine values')
grid
Result
Example 1.7
Matlab Code
clear all
close all
clc
f1=50; % Defining first frequency
f2=25;% Defining Second frequency
t=0:0.000005:0.04;% Continuous time from 0 to 0.04 with 0.000005 step
x1=sin(2*pi*f1*t); % Evaluating sine wave 1
x2=sin(2*pi*f2*t);% Evaluating sine wave 2
plot(t,x1,t,x2)% Plotting x with respect to t
title('Sine Waves of Frequency 50 Hz and 25 Hz')
xlabel('time(sec)')
ylabel('Sine values')
legend('x1(t) - 50 Hz','x2(t) - 25 Hz')
grid
Result
Example 1.8
x1(t)=5cos(2t+45o)
x2(t)=2exp(-t/2)
x3(t)=0.1t
x4(t)=5sin(2t)
Matlab Code
clear all
close all
clc
t=0:0.1:10; % Defining time
x1=5*cos(2*t+0.7854);% Evaluating x1(t). Note: Enter angle in radians.
x2=2*exp(-t/2);% Evaluating x2(t)
x3=0.1*t;% Evaluating x3(t)
x4=5*sin(2*t);% Evaluating x4(t)
plot(t,x1,'b',t,x2,'y')% Plotting x1 Vs t and x2 Vs t
hold % Holding the current plot
plot(t,x3,'r')% Plotting x3 Vs t
plot(t,x4,'g')% Plotting x4 Vs t
xlabel('t(s)')
ylabel('x(t)')
legend('x1(t)','x2(t)','x3(t)','x4(t)')
Result
Lab Exercise
1. Write a program using MATLAB to plot inverted sine wave of frequency 1KHz.
2. Write a program using MATLAB to plot 2 cycles of sine wave of frequency 10KHz.
3. Write a program using MATLAB to plot three phase sine waveof frequency 50Hz by showing
each phase 120 degree apart.
Lab Report:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Applications:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Performance Exceeds expectation Meets expectation Does not meet expectation (1-0) Marks
(5-4) (3-2)
1. Realization of Selects relevant equipment to Needs guidance to select Incapable of selecting relevant
Experiment [a, c]
the experiment, develops setup relevantequipment to the equipment to conduct the
diagrams of equipment experiment and to develop experiment, equipment connection
connections or wiring. equipment connection or wiring or wiring diagrams.
diagrams.
2. Teamwork [b] Actively engages and Cooperates with other group Distracts or discourages other group
cooperates with other group members in a reasonable manner. members from conducting the
members in an effective experiment.
manner.
3. Conducting Does proper calibration of Calibrates equipment, examines Unable to calibrate appropriate
Experiment [a, c] equipment, carefully examines equipment moving parts, and equipment, and equipment operation
equipment moving parts, and operates the equipment with minor is substantially wrong.
ensures smoothoperation error.
andprocess.
4. Laboratory Safety Respectfully and carefully Observes safety rules and procedures Disregards safety rules and
Rules [a] observes safety rules and with minor deviation. procedures.
procedures
5. Data Collection [a] Plans data collection to achieve Plans data collection to achieve Does not know how to plan data
experimental objectives, and experimental objectives, and collects collection to achieve experimental
conducts an orderlyand a complete data with minor error. goals; data collected is incomplete and
complete datacollection. contain errors.
6. Data Analysis [a] Accurately conducts simple Conducts simple computations and Unable to conductsimple statistical
computations and statistical statistical analysis using collected data analysis on collected data; noattempt to
analysis using collected data; with minor error; reasonably correlate experimental results with
correlates experimental results to correlates experimental results to known theoretical values; incapable of
known theoreticalvalues; known theoretical values; attempts to explaining measurement errors or
accounts for measurement errors account for measurement errors and parameters that affect the
and parameters that affect parameters that affect experimental experimentalresults.
experimentalresults. results.
7. Design of Able to design and implement the Able to design and partially implement Unable to design the complete solution
Experiment [d] complete solution of open-ended the complete solution of open-ended of open-ended problem with safety,
problem with safety, health and problem with safety, health and health and environment related
environment related environment related considerations. considerations.
considerations.
Total
Lecturer / Faculty
Signature: ___________
Date: 10-09-21_