0% found this document useful (0 votes)
236 views6 pages

Sns LAB NO 02 PDF

The document contains details of three lab tasks involving plotting various signals and performing operations on vectors and matrices in MATLAB. Lab Task 1 involves plotting three-phase voltages in 2D and 3D, plotting the function y=sin(1/x), and plotting a complex number on the complex plane. Lab Task 2 differentiates between matrix powers and element-wise powers, generates a random matrix, and performs various operations on a vector including replacement, multiplication, and addition. Lab Task 3 derives new vectors by modifying elements, omitting elements, and extracting elements based on their indices.

Uploaded by

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

Sns LAB NO 02 PDF

The document contains details of three lab tasks involving plotting various signals and performing operations on vectors and matrices in MATLAB. Lab Task 1 involves plotting three-phase voltages in 2D and 3D, plotting the function y=sin(1/x), and plotting a complex number on the complex plane. Lab Task 2 differentiates between matrix powers and element-wise powers, generates a random matrix, and performs various operations on a vector including replacement, multiplication, and addition. Lab Task 3 derives new vectors by modifying elements, omitting elements, and extracting elements based on their indices.

Uploaded by

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

LAB NO 02

Lab Task :01

1. Plot three phase voltage of magnitude 440v and 120-degree phase difference in 2D as well
as in 3D.
a) Use distinct colors (R, Y, B), X-label, Y-label, title, legend for each.
b) All plots overlapping in 1 fig.
c) different window for each plot.
2. Plot the function: y = sin(1/x) for time interval 0-2
(Hint: use symbolic variable and respective command)
3. Plot Complex number Z = 4+5j in complex plan.
1)
part a) Use distinct colors (R, Y, B), X-label, Y-label, title, legend for each.

CODE:

%part a
%2D
x=0:.1:2*pi;
y=-1:.01:1;
hold on;
v1=440*sin(x-(2/3*pi));
v2=440*sin(x);
v3=440*sin(x+(2/3*pi));
plot(x,v1,'r',x,v2,'y',x,v3,'b','linewidth',2)
xlabel('x axis')
ylabel('y axis')
title('3 Phase AC 2D plot')
legend('v1','v2','v3')
%_______________________________%
%3D
x=0:.1:2*pi;
y=-1:.1:1;
hold on
[x,y]=meshgrid(x,y);
v1=440*sin(x-(2/3*pi));
h1=surf(x,y,v1,'Facecolor','red','edgecolor','none','linewidth',2)
v2=440*sin(x);
h2=surf(x,y,v2,'Facecolor','yellow','edgecolor','none');
v3=440*sin(x+(2/3*pi));
h3=surf(x,y,v3,'Facecolor','blue','edgecolor','none');
xlabel('x axis')
ylabel('y axis')
zlabel('z axis')
title('3 Phase AC 3D plot')
legend('v1','v2','v3')
OUTPUT:

Part b) All plots overlapping in 1 fig.

CODE:

%part b
x=0:.1:2*pi;
y=-1:.01:1;
hold on;
disp('part 1')
subplot(1,3,1);
v1=440*sin(x-(2/3*pi));
plot(x,v1,'r');
xlabel('x axis')
ylabel('y axis')
title('phase 1')
subplot(1,3,2);
v2=440*sin(x);
plot(x,v2,'y');
xlabel('x axis')
ylabel('y axis')
title('phase 2')
c)subplot(1,3,3);
CODE:
v3=440*sin(x+(2/3*pi));
plot(x,v3,'b');
xlabel('x axis')
ylabel('y axis')
title('phase 3')
OUTPUT:

Part c) different window for each plot.


CODE:

t=0:0.1:10;
R=440*sin(t);
Y=440*sin(t+120);
B=440*sin(t-120);
figure(1)
plot(t,R,'linewidth',2);
figure(2)
plot(t,Y,'linewidth',2);
figure(3)
plot(t,B,'linewidth',2);

OUTPUT:
2) Plot the function: y = sin(1/x) for time interval 0-2.
CODE:

x = [0:0.05:4];
y = sin(x.^-1);
plot(x,y,'linewidth',3)
xlim([0 2])
xlabel('x axis');
ylabel('y axis');
title('graph of sin(1/x)');

OUTPUT:
3) Plot Complex number Z = 4+5j in complex plan.
CODE:
z = complex(4, 5);
plot(real(z), imag(z), '*');
xlabel('real axis');
ylabel('imaginary axis');
title('graph of complex no z=4+5j');

OUTPUT:

Lab Task :02

I. Take matrix A of an order 3x3 and differentiate b/w A^2, A.^2, A*A
II. Define a rectangular matrix of order 5x3 having random values b/w 0 and 8
III. For vector [1.92 , .05 ,-2.43 , -.02 , .09 , .85 , .06 , -.05 , .3214 ,3, 25 , 1
,5 ,10 , .0125 ,100]
IV. Replace any value b/w 1 and 4 with 0
V. Multiply negative values with -1
VI. Add 100 for the number that larger than or equal 5
CODE:
clear all
%part 1
A=[1 2 3;4 5 6;7 8 9];
x=A^2;y=A.^2;z=A*A;
%part 2
r = randi([0,8],5,3);
%part 3
B=[1.92 , .05 ,-2.43 , -.02 , .09 , .85 , .06 , -.05 , .3214 ,3, 25 , 1 ,5 ,10 ,
.0125 ,100];
%part 4
B(B>0.00 & B<4.00)=0;
%part 5
B(B<0)=B(B<0)*-1;
%part 6
B(B>=5)=B(B>=5)+100;
OUTPUT:

Lab Task 3:

V1=[1 2 3 4 5 6 7 8 9 0];
V2=[0.3 1.2 0.5 2.1 0.1 0.4 3.6 4.2 1.7 0.9];
V3=[4 4 4 4 3 3 2 2 2 1];
I. Derive a new vector V7 from V3, with its 7th element changed to 1.4.
II. Derive a new vector V6 from V1, with its 9th element omitted.
III. Derive a new vector V8 from V2, whose elements are prime no. indexed values of V2.
CODE:
clear all
V1=[1 2 3 4 5 6 7 8 9 0];
V2=[0.3 1.2 0.5 2.1 0.1 0.4 3.6 4.2 1.7 0.9];
V3=[4 4 4 4 3 3 2 2 2 1];
%PART 1
V7=V3;
V7(7)=1.4;
%PART 2
V6=V1;
V6(9)=[ ];
%PART 3
V8=[V2(2),V2(3),V2(5),V2(7)];
OUTPUT:

You might also like