Linear Algebra Octave Flashcards
Initialize a vector
V1 = [1 2 3]
Addition of two vectors
v1 + v2
Transpose of a vector
- v’ (hermitian)
- v.’ - regular transpose
- transpose(v) - regular transpose
Scalar multiplication
2 * v
Dot product approaches
- dp = sum (v1 .* v2)
- dp = dot(v1, v2)
- dp = v1T * v2 (v1 and v2 must be column vectors)
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)