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
Q

How to create just positive random number

A

rand

26
Q

create duplicate dependent vector from v1

A

v2 = randn/rand * v1

27
Q

absolute value of a number

A

abs(-1)

28
Q

Perform hadamard multiplication

A
  1. v1 . * v2
29
Q

What does v1 * v2 represent

A

matrix multiplication

30
Q

Outer product

A

v .* w’

31
Q

cross product of vectors

A

cross(v, w)

32
Q

create complex number

A

complex(3, 4) = 3+4i

33
Q

Create complex vector

A

v = [3 4i complex(5,2) 2-5i]

34
Q

transpose(3 + 4i) =

A

3 + 4i

35
Q

Hermitian transpose of v = 3+4i - write syntax

A

v’ * v = 25

36
Q

Unit vectors - mu =

A

1/norm(v)

37
Q

Normalize a vector

A

mu * v = norm_vector such that norm(norm_vector) = 1

38
Q

Creating an identity matrix

A

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
Q

Creating an zeros matrix

A

m = zeros(4). Can create rectangular matrices as well

40
Q

creating diagonal matrix

A

m = diag([1 2 3 4 5]); Can create rectangular matrices as well

41
Q

Creating upper triangular matrix

A

s = randn(5)
ut = triu(s); Can create rectangular matrices as well

42
Q

Creating lower triangular matrix

A

s = randn(5)
lt = tril(s); Can create rectangular matrices as well

43
Q

Concatenate two matrices

A

m1 = randn(5* 3)
m2 = randn(5 * 5)
C = [m1 m2]

44
Q

Addition of matrices

A

A+B ; both are of same dimensions

45
Q

Shifting a matrix

A

D = randn(10)
shft = D * (0.5 * eye(10))

46
Q

Two applications of diag keyword

A
  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
Q

Calculating trace

A
  1. trace(matrix)
  2. sum(diag(matrix))
48
Q

Properties that prove trace is a linear operator

A
  1. trace(a+b) = trace(a) + trace(b)
  2. l * trace(a) = trace(l*a)
    closed under both addition and subtraction
49
Q

Create a matrix with values from 1 to 12 and shape 3X4

A

A = reshape(1:12, 3,4)

50
Q

Broadcasting three ways

A

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
Q

bsxfun stands for

A

binary expansion

52
Q

Creating a symmetric matrix from a non-symmetric matrix a

A

s = (a * a’)/m^2

53
Q

Hadamard matrix multiplication

A

.* (* for regular multiplication)

54
Q

Hadamard multiplication rule

A

Both the matrices must be of same size