Experiment 1
Experiment 1
Table of Contents
Matrix Theory............................................................................................................................................................1
Creating arrays (Row and column vectors)...........................................................................................................1
Creating Matrix..................................................................................................................................................... 2
Random Matrix Generation...................................................................................................................................2
linspace Function..................................................................................................................................................2
Extraction of elements/arrays............................................................................................................................... 2
Matrix Theory
Creating arrays (Row and column vectors)
% Creating arrays
A=[1 2 3 4 5]
A = 1×5
1 2 3 4 5
B=[1;2;3;4]
B = 4×1
1
2
3
4
C=A'
C = 5×1
1
2
3
4
5
D=transpose(C)
D = 5×1
1
2
3
4
5
a = 1×5
1 2 3 4 5
b=0:0.5:3
b = 1×7
0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000
1
Creating Matrix
% Creating matrix
A=[1 2 3 4;5 6 7 8]
A = 2×4
1 2 3 4
5 6 7 8
B=[1:2:100;2:2:100]
B = 2×50
1 3 5 7 9 11 13 15 17 19 21 23 25
2 4 6 8 10 12 14 16 18 20 22 24 26
c = 3×4
0.3404 0.7513 0.6991 0.5472
0.5853 0.2551 0.8909 0.1386
0.2238 0.5060 0.9593 0.1493
mat1 = 3×5
2 5 2 4 5
5 2 1 3 3
2 5 2 2 3
mat2=randi(10,[3 5])
mat2 = 3×5
10 8 1 8 6
3 4 1 10 5
8 6 6 2 1
mat3 = 3×5
-2 -2 1 2 -5
-4 0 -3 3 -3
3 -4 2 -1 5
linspace Function
% linspace(start,end,no_of_points)
a=linspace(0,1,100);
b=linspace(0,2*pi,500);
Extraction of elements/arrays
2
% Consider the matrix A
A
A = 4×5
1 2 0 -1 4
2 5 -1 -1 2
3 10 -1 -1 2
4 0 0 5 2
A(1,5)=4 % Replaces the element in the 1st row and 5th column by 4
A = 4×5
1 2 0 -1 4
2 5 -1 -1 2
3 10 -1 -1 2
4 0 0 5 2
A2 = 4×1
2
5
10
0
A3 = 4×1
0
-1
-1
0
ans = 3×1
-1
-1
-1
ans = 1×5
2 5 -1 -1 2
ans = 1×5
4 0 0 5 2
A = 4×5
1 2 0 -1 4
2 5 -1 -1 2
3 10 -1 -1 2
4 0 0 5 2