Linear Algebra Octave Flashcards

1
Q

Initialize a vector

A

V1 = [1 2 3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Addition of two vectors

A

v1 + v2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Transpose of a vector

A
  1. v’ (hermitian)
  2. v.’ - regular transpose
  3. transpose(v) - regular transpose
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Scalar multiplication

A

2 * v

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Dot product approaches

A
  1. dp = sum (v1 .* v2)
  2. dp = dot(v1, v2)
  3. dp = v1T * v2 (v1 and v2 must be column vectors)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Create one random number

A

randn / randn()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Create random vector of size 10

A

v = randn(10, 1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Create a matrix of size 4 X 6

A

mat = randn(4, 6)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Get the size of the matrix

A

size(mat) = (4, 6)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Just get the number of rows of a matrix

A

size(mat, 1) = 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Just get the number of columns of a matrix

A

size(mat, 2) = 6 ; length(mat) = 6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Get the first column of a matrix

A

mat(:, 1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Get the first and third columns of a matrix

A

mat(:, [1,3])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Get the one to third columns of a matrix

A

mat(:, [1:3])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Repeat 1st column twice in a matrix

A

mat(:, [1,1])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Get the first row of a matrix

A

mat(1, :)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Get the first and third rows of a matrix

A

mat([1,3], :)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Get 1 to third rows in a matrix

A

mat([1:3], :)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Repeat 1st row twice in a matrix

A

mat([1,1], :)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Repeat 1st row n times in a matrix

A

mat(repelem(1,n), :)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Create a zero vector of size 4

A

zero_vector = zeros(4,1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

magnitude of a vector

A
  1. sqrt(dot(v,v))
  2. sqrt(sum(v .* v))
  3. norm(v)
23
Q

Angle between two vectors

A

theta = acos(dot(v1, v2)/(norm(v1) * norm(v2)))

24
Q

How to know if two vectors are orthogonal

A

If the dot product of the two vectors is 0

25
How to create just positive random number
rand
26
create duplicate dependent vector from v1
v2 = randn/rand * v1
27
absolute value of a number
abs(-1)
28
Perform hadamard multiplication
1. v1 . * v2
29
What does v1 * v2 represent
matrix multiplication
30
Outer product
v .* w'
31
cross product of vectors
cross(v, w)
32
create complex number
complex(3, 4) = 3+4i
33
Create complex vector
v = [3 4i complex(5,2) 2-5i]
34
transpose(3 + 4i) =
3 + 4i
35
Hermitian transpose of v = 3+4i - write syntax
v' * v = 25
36
Unit vectors - mu =
1/norm(v)
37
Normalize a vector
mu * v = norm_vector such that norm(norm_vector) = 1
38
Creating an identity matrix
m = eye(5). Can create rectangular matrices as well. 1's is equal to number of columns. But identity matrices are only square matrices in practice
39
Creating an zeros matrix
m = zeros(4). Can create rectangular matrices as well
40
creating diagonal matrix
m = diag([1 2 3 4 5]); Can create rectangular matrices as well
41
Creating upper triangular matrix
s = randn(5) ut = triu(s); Can create rectangular matrices as well
42
Creating lower triangular matrix
s = randn(5) lt = tril(s); Can create rectangular matrices as well
43
Concatenate two matrices
m1 = randn(5* 3) m2 = randn(5 * 5) C = [m1 m2]
44
Addition of matrices
A+B ; both are of same dimensions
45
Shifting a matrix
D = randn(10) shft = D * (0.5 * eye(10))
46
Two applications of diag keyword
1. diag(matrix) =pulls out the diagnoal as a row vector, [1;2;3;4;5;6] 2. diag(vector) = creates a diagonal matrix with the vector elements as diagonal.
47
Calculating trace
1. trace(matrix) 2. sum(diag(matrix))
48
Properties that prove trace is a linear operator
1. trace(a+b) = trace(a) + trace(b) 2. l * trace(a) = trace(l*a) closed under both addition and subtraction
49
Create a matrix with values from 1 to 12 and shape 3X4
A = reshape(1:12, 3,4)
50
Broadcasting three ways
a =reshape(1:12, 3,4) r = [1 2 3 4] c = [100 200 300]' 1. a + repmat(r, size(a,1), 1) a + repmat(c, 1, size(a,2))) 2. bsxfun(@plus, a, r) bsxfun(@plus, a, c) 3. a + r a + c
51
bsxfun stands for
binary expansion
52
Creating a symmetric matrix from a non-symmetric matrix a
s = (a * a')/m^2
53
Hadamard matrix multiplication
.* (* for regular multiplication)
54
Hadamard multiplication rule
Both the matrices must be of same size