Vectors & Matrices Flashcards

(20 cards)

1
Q

How do we create an array from one value to another?

Alternative with jump argument?

A

We use colons :

X = i : j (From i through j)

Alternative:

X = i : k : j

(The k is the jump value)

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

How do we transpose a matrix or vector X?

A

By using single apostrophe:

X’ is the transpose of X

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

How do we generate an array of 100 elements evenly spaced from an initial value toca final one?

A

By using: linspace(initial, final)

You can also add an extra argument:

linspace(initial, final, amount)

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

How do we manually create vectors or matrices?

A

By using brackets:

X = [1 2 3] or [1, 2, 3]

Use space or commas for separating elements in the same row.

X = [1; 2; 3]

Use semicolon for separating elements from columns.

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

Example of a matrix?

A

A = [ 1, 2; 3, 4]

This is 2x2 matrix.

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

If A is a matrix, what do the following mean?

A + 2 , A - 2 , A* 2 or 2*A, A/2

A

Those operations will add, subtract, multiply or divide by 2 to each element of the matrix A.

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

How do we apply elementwise operations to vectors or matrices?

A

We add a dot to the vector/matrix. For instance:

x.^2 will square each element

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

Most common types of matrices with commands?

A

All ones matrix: ones(m, n)
All zeros: zeros(m,n)
Identity: eye(n)

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

How do we access elements in a matrix or array?

A

We use parenthesis, for instance, if A is the matrix:

A(i, j) gives you the element in the ith row and jth column.

If A is an array, then we do:

A(j) access the jth element.

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

How do we access the last element of an array A?

A

By following this command:

A(end)

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

How can I assign a value to an entry of a matrix or array A?

A

By doing this: A(i, j) = value

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

What if i wanted to obtain all elements of a row or column of a matrix A?

A

A(2, : ) gives you all elements of the second row of the matrix

A(: , 2) gives you all elements of the second column

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

How can I access ranges of a matrix? For instance, suppose you have a 4x4 matrix and you want to get the second and third row and second and third column.

A

By using this command:

A(2:3 , 2:3)

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

How do we do element by element multiplication or division in matlab?

A

A.*B & A./B

We put a dot before the multiplication or division sign

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

How do we do inner product between two vectors?

A

X * Y’ (Multiplying by transpose)

dot(X, Y) (Built in function)

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

How can we do cross product I’m Matlab?

A

By doing the following:

cross(x, y)

17
Q

How to read csv files?

A

A = csvread(name.csv)

This is saved as a matrix

18
Q

How to write and create a csv file?

A

csvwrite(“name.csv”, matrix)

19
Q

How to save workspace on a file?

A

Using the command:

save(“my_workspace.mat”)

20
Q

How to load a workspace that’s on a file?

A

Using the command:

load(“my_workspace.mat”)