1
Problem Statements :(ii) Study of basic matrix operations using MATLAB.
1. Create a matrix A of size 4 4 in MATLAB given by,
11
A = [21
31
41
12
22
32
42
13
22
33
43
14
24]
34
44
12
13
14
21
22
23
24
31
32
33
34
41
42
43
44
Size =
4
2014BEL005
OUTPUT :
a2 =
23
b2 =
12
22
32
42
c2 =
31
32
33
34
d2 =
12
13
22
23
32
33
42
43
22
23
32
33
42
43
11
13
21
23
31
33
41
43
e2 =
f2 =
2014BEL005
g2 =
43
h2 =
11
21
31
41
12
22
32
42
13
23
33
43
14
24
34
44
i2 =
11
12
13
14
21
22
23
24
31
32
33
34
41
42
43
44
2014BEL005
j2 =
11
22
33
44
k2 =
12
23
34
l2 =
21
32
43
m2 =
13
24
2014BEL005
b3 =
1
c3 =
d3 =
0.2963
0.7447
0.1890
0.6868
0.1835
-0.3349
0.6601
0.0230
-0.2097
0.3071
0.5528
-0.0679
0.0513
0.6252
0.1352
1.0391
-0.1952
0.8261
0.1832
0.5152
-1.1176
-0.2176
1.5270
-1.0298
0.2614
1.2607
-0.3031
0.4669
0.9492
-0.9415
e3 =
F =
a4 =
1
2014BEL005
(b) Find the result of following operation for the matrix A defined in
problem 1:
B = [A [ones(2, 2); eye(2)] ]
OUTPUT :
b4 =
11
21
31
41
12
22
32
42
13
23
33
43
14
24
34
44
1
1
1
0
1
1
0
1
12
22
c4 =
11
21
11
21
12
22
12
22
11
21
11
21
12
22
12
22
11
21
11
21
12
22
12
22
2014BEL005
a5 =
1
16
25
36
49
64
81
30
36
42
66
81
96
102
126
150
b5 =
c5 =
d5 =
1.0e+16 *
-0.4504
0.9007
-0.4504
0.9007
-1.8014
0.9007
-0.4504
0.9007
-0.4504
-15.0000
-18.0000
e5 =
2
f5 =
1.0000
-0.0000
g5 =
16.1168
-1.1168
-0.
2014BEL005
3. In the new figure window, plot the following using subplot command:
(a) sin(t) w. r. t. cos(t).
(b) sin(2t) w. r. t. cos(t).
(c) sin(3t) w. r. t. cos(t).
(d) sin(4t) w. r. t. cos(t).
OUTPUT :
2014BEL005
4. Draw a 3-D plot which contain values of cos(3t) and sin(3t) drawn w. r. t.
time t.
OUTPUT :
RESULT :
MATLAB (Matrix laboratory) is an interactive software system for numerical
computations and graphics. As the name suggests, MATLAB is especially designed for
matrix computations: solving systems of linear equations, computing eigenvalues and
eigenvectors, factoring matrices, and so forth. In addition, it has a variety of graphical
capabilities, and can be extended through programs written in its own programming
language.
CONCLUSION :
In this way we have studied Introduction to MATLAB software, basic matrix
operations and basic plotting tools available in MATLAB.
2014BEL005
PROGRAM :
clc;
clear all;
disp('(ii) Study of basic matrix operations using MATLAB.')
A=[11 12 13 14;21 22 23 24;31 32 33 34;41 42 43 44]
Size=size(A)
a2=A(2,3)
b2=A(:,2)
c2=A(3,:)
d2=A(:,2:3)
e2=A(2:4,2:3)
f2=A(:,1:2:3)
g2=A(12)
h2=A(:)
i2=A(:,:)
j2=diag(A)
k2=diag(A,1)
l2=diag(A,-1)
m2=diag(A,2)
a3=zeros(2,3)
b3=ones(2)
c3=eye(3)
d3=rand(1,5)
e3=randn(5)
E=[1 2 3 4 5 6]
F=[1 2 3 4]
a4=[E,F]
% a4=cat(2,E,F)
b4=[A [ones(2); eye(2)] ]
C=[11 12;21 22]
c4=repmat(C,2,3)
D=[1 2 3;4 5 6;7 8 9]
a5=D.^2
b5=D^2
c5=D'
d5=inv(D)
e5=rank(D)
f5=poly(D)
g5=eig(D)
disp('(iii) Study of basic plotting tools available in
MATLAB.')
t=0:0.01:25;
% S=sin(0.002*pi*f*t)
figure(1)
S=sin(t)
subplot(1,2,1)
plot(t,S)
grid on
xlabel('Time')
ylabel('Amplitude')
2014BEL005
title('Sine Wave')
T=cos(t)
subplot(1,2,2)
plot(t,T)
grid on
xlabel('Time')
ylabel('Amplitude')
title('Cosine Wave')
figure(2)
subplot(2,2,1)
plot(cos(t),sin(t))
grid on
xlabel('Cos(t)')
ylabel('Sin(t)')
subplot(2,2,2)
plot(cos(t),sin(2*t))
grid on
xlabel('Cos(t)')
ylabel('Sin(2t)')
subplot(2,2,3)
plot(cos(t),sin(3*t))
grid on
xlabel('Cos(t)')
ylabel('Sin(3t)')
subplot(2,2,4)
plot(cos(t),sin(4*t))
grid on
xlabel('Cos(t)')
ylabel('Sin(4t)')
figure(3)
t=0:0.01:100;
plot3(sin(3*t),cos(3*t),t)
grid on
xlabel('Sin(3t)')
ylabel('cos(3t)')
zlabel('t')
title('3D plot of sin(3t) and cos(3t) w.r.t time t')
2014BEL005