Professional Documents
Culture Documents
Signals AND Systems Lab: Experiment-1
Signals AND Systems Lab: Experiment-1
Signals AND Systems Lab: Experiment-1
AND
SYSTEMS LAB
Submitted by:
Aakanksha Bansal(09103410)
Ashima Agrawal(09103408)
Batch:B1
EXPERIMENT-1
Aim: Introduction to MATLAB and its various applications.
Theory:
Z = trapz(Y) computes an approximation of the integral of Y via
the trapezoidal method (with unit spacing). To compute the
integral for spacing other than one, multiply Z by the spacing
increment. Input Y can be complex.
Ans:
aVec = [3.14 15 9 26];
bVec = [2.71;8;28;182];
cVec = [5 :-0.2 :-5];
dVec = logspace(0,1,100);
eVec = ['hello'];
mat1=ones(9,9)
mat1 =
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
>>amat = amat=2.*mat1
amat =
2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2
3(b)
v=[1,2,3,4,5,4,3,2,1]
bmat=zeros(9,9)
bmat=diag(v,0)
b=
1 0 0 0 0 0 0 0 0
0 2 0 0 0 0 0 0 0
0 0 3 0 0 0 0 0 0
0 0 0 4 0 0 0 0 0
0 0 0 0 5 0 0 0 0
0 0 0 0 0 4 0 0 0
0 0 0 0 0 0 3 0 0
0 0 0 0 0 0 0 2 0
0 0 0 0 0 0 0 0 1
3(c)
incr = 1:1:100;
cmat=reshape(incr,10,10)
cmat = reshape(x,10,10);
>>cmat = reshape(x,10,10)
cmat =
1 11 21 31 41 51 61 71 81 91
2 12 22 32 42 52 62 72 82 92
3 13 23 33 43 53 63 73 83 93
4 14 24 34 44 54 64 74 84 94
5 15 25 35 45 55 65 75 85 95
6 16 26 36 46 56 66 76 86 96
7 17 27 37 47 57 67 77 87 97
8 18 28 38 48 58 68 78 88 98
9 19 29 39 49 59 69 79 89 99
10 20 30 40 50 60 70 80 90 100
3(d)
mat3=ones(3,4)
dmat=mat3.*NaN
dmat=
NaNNaNNaNNaN
NaNNaNNaNNaN
NaNNaNNaNNaN
3(e)
emat = [13 -1 -5; -22 10 -87];
emat =
13 -1 -5
-22 10 -87
3(f)
fmat = ceil(-3 + 6.*rand(5,3));
fmat =
0 0 -1
-1 2 2
-1 1 2
1 1 0
0 3 1
Q4).Common functions and indexing.
Ans)
4(a)
cSum =sum(cmat);
4(b)
cMean =mean(cmat);
4(c)
emat(1,:) = [1 1 1];
4(d)
cSub = cmat(2:9,2:9)
4(e)
lin = 1:1:20;
for j=1:20
if(mod(lin(j),2)==0)
lin(j)=-j;
end;
end;
4(f)
r=rand(1,5)
a=find(r<0.5)
r(a)=0
Ans)
t = linspace (0, 2*pi ,1000);
plot (t,sin(t));
hold on;
plot (t,cos(t),'--r');
p =plot (t,sin(t));
q =plot (t,cos(t),'--r');
legend (p,'sinwave','location','North');
legend (q,'coswave','location','South');
xlim([0 2*pi]);
ylim([-1.4 1.4]);
t = linspace(0,2*pi,1000);
a = input('enter the x coord of the centre');
b = input('enter the y coord of the centre');
c= input('enter the radius of the circle');
x = r*cos(t)+a;
y = r*sin(t)+b;
plot(x,y);
7. Loops and flow control. Make function called loopTest(N) that loops
through the
values 1 through N and for each number n it should display ‘n is divisible
by 2’, ‘n is
divisible by 3’, ‘n is divisible by 2 AND 3’ or ‘n is NOT divisible by 2 or
3’. Use a for
loop, the function mod or rem to figure out if a number is divisible by
2 or 3, and num2str
to convert each number to a string for displaying. You can use any
combination of if, else,
andelseif.
Ans)
for j=1:p
if (mod(j,3)==0 && mod(j,2)==0)
disp(j);
elseif(mod(j,3)==0)
disp('div by 3');
disp(j);
else if(mod(j,2)==0)
disp('div by 2');
disp(j);
else
disp('div by none');
disp(j);
end;
end;
end;
Q8)
Linear system of equations.Solve the following system of
equations:
3a + 6b + 4c = 1. a + 5b = 2. 7b + 7c = 3
Ans)
A=[3,6,4;1,5,0;0,7,7]
b=[1;2;3]
x=A\b
x=
-0.5824
0.5165
-0.0879
Q9)Numerical integration.Use trapzor quad. What is the value of :
Compute and display the difference between your numerical answer and the
analytical answer: −24 e−5/3+ 9
Ans)
x = 0:0.01:5;
y=x.*exp(-x*1/3)
z=trapz(x,y)
w=4.3736
difference=w-z
diff =
0.0934
Q10)Practice with cells.Usually, cells are most useful for storing strings, because
thelength of each string can be unique. a. Make a 3x3 cell where the first column contains
the names: ‘Joe’, ’Sarah’, and ’Pat’, the second column contains their last names:
‘Smith’,‘Brown’, ‘Jackson’, and the third column contains their salaries: $30,000,
$150,000, and $120,000. Display the cell using disp.
Ans)
z=cell(3)
z(1,:)={'joe','smith','$30000'}
z(2,:)={'sarah','brown','$150000'}
z(3,:)={'pat','jackson','$120000'}
disp(z)
LEARNING OUTCOME
1. Creating a file and saving to the directory.
2. Working with matrix of size of mxn and using the dot operator.
3. Using various predefined mathematical operators