Professional Documents
Culture Documents
ID: 180021334
%task 1
ans = 10×10
0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10 11
3 4 5 6 7 8 9 10 11 12
4 5 6 7 8 9 10 11 12 13
5 6 7 8 9 10 11 12 13 14
6 7 8 9 10 11 12 13 14 15
7 8 9 10 11 12 13 14 15 16
8 9 10 11 12 13 14 15 16 17
9 10 11 12 13 14 15 16 17 18
%task 2
x = 5×5
5.8299 8.2438 1.0777 5.9436 1.7877
2.5181 9.8266 9.0631 0.2251 4.2289
2.9044 7.3025 8.7965 4.2526 0.9423
6.1709 3.4388 8.1776 3.1272 5.9852
2.6528 5.8407 2.6073 1.6148 4.7092
x(3,:) = rand(1,5); %all the 3rd row elements replaced with 5 random numbers from 0 to 1
x
x = 5×5
5.8299 8.2438 1.0777 5.9436 1.7877
2.5181 9.8266 9.0631 0.2251 4.2289
0.6959 0.6999 0.6385 0.0336 0.0688
6.1709 3.4388 8.1776 3.1272 5.9852
2.6528 5.8407 2.6073 1.6148 4.7092
v=num2cell(randi(4,1,2)); % a random 1*2 cell generated with values upto 4 as the matrix siz
[r,c] = v{:}; % random row and column number is collected from v cell
y = x(r:r+1,c:c+1) % random 2*2 matrix generated
y = 2×2
9.0631 0.2251
0.6385 0.0336
ans = 2×2
0.2090 -1.4000
-3.9709 56.3609
1
%task 3
%task 4
f = 334;
t = 0 : 0.001 : 1;
F = @(x,y) sin(2*pi*y*x);
s = zeros(1,length(t));
for i = 1 : 8
s = s + F(t,f+2*(i-1));
figure(1)
subplot(8,1,i)
plot(t,s)
end
2
3
%task 6
x = sin(linspace(0,10*pi,100));
p = x(x>0); %stores the greater than 0 numbers of x in p
length(p)
ans = 49
%task 7
a = 5;
f = 20;
d = 0.6;
T = 1/f;
t = 0 : 0.0001 : 1;
F = @(x,y,z,w) w*((mod(x,y)<=z*y)-(mod(x,y)>z*y));
s = F(t,T,d,a);
plot(t,s,'linewidth',3)
grid on
axis([0 0.3 -10 10])
%task 8
1
a = 5;
f = 20;
w = 2*pi*f;
t = 0 : 0.0001 : 1;
s = a*sawtooth(w*t);
plot(t,s,'linewidth',3)
grid on
axis([0 0.3 -10 10])
%task 9
t = -1 : 0.001 : 4;
s1 = f1(t,0,1,2,3);
s2 = f2(t,0,2,3);
2
figure(1)
plot(t,s1,'linewidth',3)
grid on
axis([-1 4 -2 2])
figure(2)
plot(t,s2,'linewidth',3)
grid on
axis([-1 4 -2 3])
3
4