Vectors & Matrices Flashcards
How do we create an array from one value to another?
Alternative with jump argument?
We use colons :
X = i : j (From i through j)
Alternative:
X = i : k : j
(The k is the jump value)
How do we transpose a matrix or vector X?
By using single apostrophe:
X’ is the transpose of X
How do we generate an array of 100 elements evenly spaced from an initial value toca final one?
By using: linspace(initial, final)
You can also add an extra argument:
linspace(initial, final, amount)
How do we manually create vectors or matrices?
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.
Example of a matrix?
A = [ 1, 2; 3, 4]
This is 2x2 matrix.
If A is a matrix, what do the following mean?
A + 2 , A - 2 , A* 2 or 2*A, A/2
Those operations will add, subtract, multiply or divide by 2 to each element of the matrix A.
How do we apply elementwise operations to vectors or matrices?
We add a dot to the vector/matrix. For instance:
x.^2 will square each element
Most common types of matrices with commands?
All ones matrix: ones(m, n)
All zeros: zeros(m,n)
Identity: eye(n)
How do we access elements in a matrix or array?
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 do we access the last element of an array A?
By following this command:
A(end)
How can I assign a value to an entry of a matrix or array A?
By doing this: A(i, j) = value
What if i wanted to obtain all elements of a row or column of a matrix A?
A(2, : ) gives you all elements of the second row of the matrix
A(: , 2) gives you all elements of the second column