Sns Lab Mannual For Mid
Sns Lab Mannual For Mid
Electrical Engineering
Exercise No. 1
Q No. 1:
>> A=32:2:75
A =32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74
>> B=75:2:131
B =Columns 1 through 22
75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115
117
Columns 23 through 29
119 121 123 125 127 129 131
>> C=1:100
C =Columns 1 through 22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Columns 23 through 44
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
Columns 45 through 66
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
Columns 67 through 88
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
Columns 89 through 100
89 90 91 92 93 94 95 96 97 98 99 100
Q. No. 2:
>> x=[2 5 1 6]
x =2 5 1 6
>> x+16
ans =18 21 17 22
>> j=1:2:4;
>>x(j)=x(j)+3
x =5 5 4 6
>> s=x.^2
s =25 25 16 36
>>sr= sqrt (x)
sr =2.2361 2.2361 2.0000 2.4495
Q. No. 3:
>> x=[3 2 6 8]';
>> y=[4 1 3 5]';
>>a=x+y
a=
7
3
9
13
FUUAST,Islamabad-Pakistan
>>b=x.^y
b=
81
2
216
32768
>>d= y./x
d =1.3333
0.5000
0.5000
0.6250
>> z=x.*y
z=
12
2
18
40
>> w=sum(z)
w =72
>>x'*y - w
ans =0
Q. No. 4:
>> 2 / 2 * 3
ans =3
>> 6 - 2 / 5 + 7 ^ 2 - 1
ans =53.6000
>> 10 / 2 \ 5 - 3 + 2 * 4
ans =6
>> 3 ^ 2 / 4
ans =2.2500
>> 3 ^ 2 ^ 2
ans =81
>> 2 + round (6 / 9 + 3 * 2) / 2 - 3
ans =2.5000
>> 2 + floor (6 / 9 + 3 * 2) / 2 - 3
ans =2
Q. No. 5:
(a):
>> x=2:2:10
x =2 4 6 8 10
(b):
>> x=10:-2:-4
x =10 8 6 4 2 0 -2 -4
(c):
Electrical Engineering
FUUAST,Islamabad-Pakistan
Electrical Engineering
>> x=1:10;
>> x=1./x;
>>rats(x)
ans =1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9
(d):
>> x=1:11;
>> y=0:10;
>> z=y./x;
>>rats(z)
ans =0 1/2 2/3 3/4 4/5 5/6 6/7 7/8 8/9
Q. No.6:
>> n=1:100;
>> x=(-1).^(n+1)./((2*n)-1);
>>sum(x)
ans =0.7829
Q. No.7:
(a):
>> b=[1:10];
>> p=[1:10];
>> h=sqrt((p.^2)+(b.^2));
h =1.4142 2.8284 4.2426 5.6569 7.0711 8.4853 9.8995 11.3137 12.7279 14.1421
(b):
>> b=[1:10];
>> a=[1:10];
>> t=45;
>>s_c=(a.^2)+(b.^2)-a.*b.*cos(t);
>> c=sqrt(s_c)
c =1.2144 2.4287 3.6431 4.8575 6.0718 7.2862 8.5005 9.7149 10.9293 12.1436
Q. No.8:
(a):
>> t=1:5;
>>log(2+t+t.^2)
ans =
1.3863 2.0794 2.6391 3.0910 3.4657
(b):
>>exp(t).*(1+cos(3*t))
ans =
0.0272 14.4838 1.7850 100.6710 35.6655
FUUAST,Islamabad-Pakistan
Electrical Engineering
Exercise No. 2
Q. No. 1:
Ans: >> x=pascal(5)
x=
11111
12345
1 3 6 10 15
1 4 10 20 35
1 5 15 35 70
>> x'
ans =
11111
12345
1 3 6 10 15
1 4 10 20 35
1 5 15 35 70 x=x, symmetric.
Q. No.2:
Ans: >> f=fix(10*rand(3,5))
f=
17063
49876
96971
Q. No. 4:
a. Ans: >> d=[1+2j 3;7 5j]
d=
1.0000 + 2.0000i
3.0000
7.0000
0 + 5.0000i
>> e=[2+3j 5+5j;0 1-8j]
e=
2.0000 + 3.0000i
5.0000 + 5.0000i
0
1.0000 - 8.0000i
>> c=d+e
c =3.0000 + 5.0000i
8.0000 + 5.0000i
7.0000
1.0000 - 3.0000i
b. Ans: >> c=d-e
c=
-1.0000 - 1.0000i
-2.0000 - 5.0000i
7.0000
-1.0000 +13.0000i
c. Ans: >> c=d.*e
c=
-4.0000 + 7.0000i
15.0000 +15.0000i
0
40.0000 + 5.0000i
d. Ans: >> c=d./e
c=
FUUAST,Islamabad-Pakistan
0.6154 + 0.0769i
Inf
Q. No. 5:
Ans: t=0:0.001:150;
y=3*exp(3*pi*t);
plot(t,y)
0.3000 - 0.3000i
-0.6154 + 0.0769i
Electrical Engineering
FUUAST,Islamabad-Pakistan
Electrical Engineering
Exercise No. 3
Q. No. 1:
>> a=[1 2 3 4 5];
>>for i=1:5;
b(i)=a(i)^a(i);
end
>>b
b =1 4 27 256 3125
Q. No. 2:
>> i=1:5;
>>b(i)=a(i).^i;
>>b
b =1 4 27 256 3125
Q. No. 4:
>> prod=1;
>> x=20:20:200;
>>for i=1:length(x);
prod=prod*x(i);
end
>> prod
prod =3.7159e+019
Q. No. 5:
>> i=1:10;
>> z=1;
>>while(z<=10)
b(z)=5^i(z);
z=z+1;
end
>>b
b =5 25 125 625 3125 15625 78125 390625 1953125 9765625
Q. No. 6:
The Example 7 will give the output c is neither 1 nor 2 if we change c=2 by c=3.
FUUAST,Islamabad-Pakistan
Electrical Engineering
Exercise No. 4
Q. No. 1:
n=-5:1:2;
y=zeros(1,8);
y(1)=6;
y(3)=2;
y(5)=1;
y(6)=5;
y(8)=-7;
stem(n,y)
title ('E1')
axis([-6 3 0 7])
Q. No. 2:
>> L=5;
>>inc=0.01;
>> t=-L:inc:L;
>>leng=length(t);
>> n0=0;
>>x1=zeros(1,leng);
FUUAST,Islamabad-Pakistan
>>x1(((L+n0)/inc+1:leng))=1;
>>x2=t.*x1;
>>x3=(t-1).*x1;
>> n0=2;
>>x4=zeros(1,leng);
>>x4(((L+n0)/inc+1:leng))=1;
>> y=(3*x1)+x2-x3+(-5*x4);
>>plot(t,y);
Q. No. 3:
(A).
n=-6:1:6;
y=[zeros(1,4) ones(1,4) zeros(1,5)];
stem(n,y)
title ('E3 A')
axis([-6 6 -2 2])
Electrical Engineering
FUUAST,Islamabad-Pakistan
Q. No. 3:
(B).
n=-10:1:10;
y=[zeros(1,3) 1 0 -1 zeros(1,11) -2 zeros(1,3)];
stem(n,y)
title ('E3 B')
axis([-10 10 -2 2])
Electrical Engineering
FUUAST,Islamabad-Pakistan
Q. No. 3:
(C).
n=-6:0.01:6;
y=[zeros(1,4) ones(1,5) zeros(1,4)];
plot(n,y)
title ('E3 C')
axis([-6 6 0 2])
Q. No. 3:
(D).
n=-5:1:5;
y=[zeros(1,4) 2 0 1 0 -3 zeros(1,2)];
stem(n,y)
title ('E3 D')
axis([-5 5 -3 2])
Electrical Engineering
FUUAST,Islamabad-Pakistan
Q. No. 4:
>> L=40;
>> n=-L:4:L;
>> x=zeros(1,length(n));
>>for i=-L:4:L;
x((L/4)+(i/4)+1)=i;
end
>>stem(n,x);
Electrical Engineering