Kathmandu School of Engineering University Department of Electrical & Electronics Engineering
Kathmandu School of Engineering University Department of Electrical & Electronics Engineering
School of Engineering
UNIVERSITY
Department of Electrical & Electronics Engineering
NETWORK ANALYSIS LABORATORY EXERCISE-I
1. Introduction to MATLAB
1.1 Basic arithmetic operations
Example-1.1.1
>> 5+4/2
ans =
7
>> (5+5)/3
ans =
3.3333
>> 9^(1/3)+16^0.3
ans =
4.3775
Example-1.1.2
>> x = 2+j*3
x=
2.0000 + 3.0000i
>> q = imag(x)
q=
3
>> p = real(x)
p=
2
>> r=conj(x)
r=
2.0000 - 3.0000i
>> m=abs(x)
m=
3.6056
>> theta=angle(x)
theta =
0.9828
Example-1.1.3
>> p=2
p=
2
>> q=3
q=
3
>> [theta,m]=cart2pol(p,q)
theta =
0.9828
m=
3.6056
>> [p,q]=pol2cart(theta,m)
p=
2
q=
3.0000
>> B=[1:10]
B=
1 2 3
9 10
1
>> A=[1 2 3; 4 5 6; 7 8 9]
A=
1 2 3
4 5 6
7 8 9
X=
5.0000 6.0000 0.5000
4.0000 10.0000 3.0000
>> size(X)
ans =
2 3
Example-1.2.2
>> A=[ 1 2 3; 4 5 6; 7 8 9]
A=
1 2 3
4 5 6
7 8 9
>> B=[0 2 4; 1 3 5; 4 6 2]
B=
0 2 4
1 3 5
4 6 2
>> C=A*B
C=
14 26 20
29 59 53
44 92 86
>> D=A'
D=
1 4 7
2 5 8
3 6 9
>> D=inv(A)
D=
1.0e+16 *
>> C = A+B
C=
1 4 7
5 8 11
11 14 11
>> C=A-B
C=
1 0 -1
3 2 1
3 2 7
>> det(A)
ans =
6.6613e-16
>> C=A/B
C=
-0.5000 1.0000
-3.5000 4.0000
-6.5000 7.0000
0
0
0
6
2
>> mean(v)
ans =
4.1667
>> min(v)
ans =
0
>> median(v)
ans =
4.5000
>> [a,n]=max(v)
a=
8
n=
4
>> std(v)
ans =
2.8577
>> max(v)
ans =
8
>> sum(v)
ans =
25
>> sort(v)
ans =
0 2 4
2008
2009
>> plot(X,Y)
>> grid
100
100
95
95
90
90
85
85
2004 2004.5 2005 2005.5 2006 2006.5 2007 2007.5 2008 2008.5 2009
1.5
2.5
3.5
4.5
5.5
Example-1.5.2
>> f=50;
>> w=2*pi*f;
>> t=0:1e-3:0.04;
>> x=w*t;
>> y=sin(x);
>> plot(t,y);
>> grid
0.8
0.8
0.6
0.6
0.4
0.4
0.2
0.2
voltage
-0.2
-0.2
-0.4
-0.4
-0.6
-0.6
-0.8
-0.8
-1
0.005
0.01
0.015
0.02
0.025
0.03
0.035
0.04
voltage plot
-1
0.005
0.01
0.015
0.02
time
0.025
0.03
0.035
0.04
Example-1.5.3
>> f=50;
>> w=2*pi*f;
>> t=0:1e-3:0.04;
>> x=w*t;
>> y=sin(x);
>> plot(x,y,'r - d');
>> grid
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
Example-1.5.5
>> t=0:1e-3:0.04;
>> f=50;
>> w=2*pi*f;
>> phi=pi/3;
>> v=5*sin(w*t);
>> i=2*sin((w*t)-phi);
>> plot(t,v);
>> grid;
>> title('multiple plots');
>> xlabel('time (sec)');
>> ylabel('voltage & current');
>> hold on;
>> plot(t,i,'r o');
-1
0
10
12
14
multiple plots
5
4
3
2
1
0
-1
-2
-3
-4
-5
0
0.005
0.01
0.015
0.02
0.025
time (sec)
0.03
0.035
0.04
multiple plots
5
4
3
2
Example-1.5.4
>> t=0:1e-3:0.04;
>> f=50;
>> w=2*pi*f;
>> phi=pi/3;
>> v=5*sin(w*t);
>> i=2*sin((w*t)-phi);
>> plot(t,v,t,i);
>> title('multiple plots');
>> xlabel('time (sec)');
>> ylabel('voltage & current');
>> grid;
1
0
-1
-2
-3
-4
-5
0
0.005
0.01
0.015
0.02
0.025
time (sec)
0.03
0.035
0.04
Example-1.5.6
>> t=0:1e-3:0.04;
>> f=50;
>> phi=pi/3;
>> v=5*sin(w*t);
>> i=2*sin((w*t)-phi);
>> subplot(2,1,1);
5
-5
0
0.005
0.01
0.015
0.02
time
0.025
0.03
0.035
0.04
0.005
0.01
0.015
0.02
time
0.025
0.03
0.035
0.04
2
1
current
>> subplot(2,1,1);
>> plot(t,v);
>> grid
>> xlabel('time');
>> ylabel('voltage');
>> subplot(2,1,2);
>> subplot(2,1,2);
>> plot(t,i);
>> grid
>> xlabel('time')
>> ylabel('current')
voltage
0
-1
-2
0
Example-1.6.1
(
) .
Plot of =
.
using mesh
>> t=-4:0.3:4;
>> [x,y]=meshgrid(t,t);
>> z=sin(x).*cos(y).*exp(-(x.^2+y.^2).^0.5);
>> mesh(x,y,z)
0.2
0
-0.2
-0.4
4
2
0
-2
-4
Example-1.6.2
Cylindrical surface created by p = 3 + sint
using cylinder function
-2
-4
1
0.8
>> t=0:pi/5:6*pi;
>> p=3+sin(t);
>> cylinder(p)
0.6
0.4
0.2
0
4
2
0
-2
-4
-4
-2
1
0.9
0.8
0.7
current (amp)
0.6
0.5
0.4
0.3
0.2
0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
time(sec)
0.7
0.8
0.9
1.5
current (amp)
0.5
0.1
0.2
0.3
0.4
0.5
0.6
time(sec)
0.7
0.8
0.9
-3
Step Response
x 10
2.5
Amplitude
1.5
0.5
0
0
0.2
0.4
0.6
0.8
1.2
Time (seconds)
Also determine the value of Mp, tp, ts and tr from the plot. Right click on the plot and click to
characteristics and find the values.
-3
Step Response
x 10
2.5
System: sys
Peak amplitude: 0.00297
Overshoot (%): 48.5
At time (seconds): 0.147
System: sys
Settling time (seconds): 0.756
Amplitude
1.5
System: sys
Rise time (seconds): 0.0551
0.5
0
0
0.2
0.4
0.6
0.8
1.2
Time (seconds)
den =
1 9 45 87 50
Assignments:
1. For the matrix equation below, AX = B, determine the vector X.
4 2 10
10
= 32
2 10 12
4 6 16
16
3.5
68
4.0
82
4.5
96
5.0
123
4. Plot the curve v = 10sin (t), where t varies from 0 to 4. Label the axis and give a
suitable title.
5. Determine the time response of the second order system defined by the transfer function:
( )=
+2
+
Consider wn = 1 and z(zeta) = 0.1, and plot the step response of the system. Also plot the
response by varying the value of zeta as z =1, 0, 2, and 0.5 on the previous plot (use hold on
code). Comment on the nature of curves for different values of zeta.
6. Obtain the Bode plot of the system whose open loop transfer function is given as below,
also find Gain margin and phase margin. Comment on the stability of the system
(a) ( ) ( ) =
(b) ( ) ( ) =
)(
(
. )
)
10