Initialize a vector
V1 = [1 2 3]
Addition of two vectors
v1 + v2
Transpose of a vector
Scalar multiplication
2 * v
Dot product approaches
Create one random number
randn / randn()
Create random vector of size 10
v = randn(10, 1)
Create a matrix of size 4 X 6
mat = randn(4, 6)
Get the size of the matrix
size(mat) = (4, 6)
Just get the number of rows of a matrix
size(mat, 1) = 4
Just get the number of columns of a matrix
size(mat, 2) = 6 ; length(mat) = 6
Get the first column of a matrix
mat(:, 1)
Get the first and third columns of a matrix
mat(:, [1,3])
Get the one to third columns of a matrix
mat(:, [1:3])
Repeat 1st column twice in a matrix
mat(:, [1,1])
Get the first row of a matrix
mat(1, :)
Get the first and third rows of a matrix
mat([1,3], :)
Get 1 to third rows in a matrix
mat([1:3], :)
Repeat 1st row twice in a matrix
mat([1,1], :)
Repeat 1st row n times in a matrix
mat(repelem(1,n), :)
Create a zero vector of size 4
zero_vector = zeros(4,1)
magnitude of a vector
Angle between two vectors
theta = acos(dot(v1, v2)/(norm(v1) * norm(v2)))
How to know if two vectors are orthogonal
If the dot product of the two vectors is 0