CS Lab1,2
CS Lab1,2
a = [ 2 4 7 5]
b = [1 3 8 9]
a (2)
sum = a+b
diff = a-b
ab = [a b]
ab (2:6);
a'
Task2 Investigate the effect of the following commands
a = [2 4 7 5]
b = [1 3 8 9]
z = [1;1;0;0]
z'
z*a
[a;b]
a*z
[z;a']
z+a'
Task3 Investigate the effect of the following commands:
M = [1 2; 3 4]
z = [1;1;0;0]
N =inv(M)
M*N
I = eye(2)
M+1
M*z(1:2)
a(3:4)*M
M(1,1)
M(1:2,1:2)
M(:,1)
M(2,:)
Task4
Use the help command to find out about the following built-in functions and make up your own simple examples:
X = zeros(4)
w = ones(2,6)
a = [2 4 6;5 3 2;7,8,2]
det(a)
y = linspace(-5,5,7)
v = logspace(1,5)
V=
1.0e+05 *
Columns 1 through 16
0.0001 0.0001 0.0001 0.0002 0.0002 0.0003 0.0003 0.0004 0.0004 0.0005 0.0007 0.0008
0.0010 0.0012 0.0014 0.0017
Columns 17 through 32
0.0020 0.0024 0.0029 0.0036 0.0043 0.0052 0.0063 0.0075 0.0091 0.0110 0.0133 0.0160
0.0193 0.0233 0.0281 0.0339
Columns 33 through 48
0.0409 0.0494 0.0596 0.0720 0.0869 0.1048 0.1265 0.1526 0.1842 0.2223 0.2683 0.3237
0.3907 0.4715 0.5690 0.6866
Columns 49 through 50
0.8286 1.0000
Task5
1. Generate a vector yc containing the values of cos(t) for the same time range as before.
t = linspace(0,20,100);
yc = cos(t);
plot (t,yc)
xlabel('Time in seconds')
ylabel('cos(t)')
title("19MTE10")
grid
2. From the “help” entry for “plot” find out how to get both ys and yc plotted
against t on the same axis.
t = linspace(0,20,100);
yc = cos(t);
ys = sin(t);
plot(t,ys,t,yc);
xlabel('Time in seconds')
title("19MTE10")
grid
legend('cos(t)', 'sin(t)')
3. From the “help” entry for “subplot” find out how to plot ys and yc plotted
on two separate graphs, one above the other.
subplot(2,1,1);
t = linspace(0,20,100);
yc = cos(t);
plot(t,yc)
xlabel('Time in seconds')
ylabel('cos(t)')
title("19MTE10")
grid
subplot(2,1,2);
ys = sin(t);
plot(t,ys)
xlabel('Time in seconds')
ylabel('sin(t)')
title("19MTE10")
grid
LAB 02
Task: `
For each of the following, separately:
a) Write code using MATLAB to create a transfer function.
b) Use tf data command
c) Find the inverse Laplace transform
d) For any two of the above, use the print sys command to check the entered transfer
function