In [1]:
% The ; denotes we are going back to a new row.
A = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12]
In [2]:
% Initialize a vector
v = [1;2;3]
In [3]:
% Get the dimension of the matrix A where m = rows and n = columns
[m,n] = size(A)
In [4]:
% You could also store it this way
dim_A = size(A)
In [5]:
% Get the dimension of the vector v
dim_v = size(v)
In [6]:
% Now let's index into the 2nd row 3rd column of matrix A
A_23 = A(2,3)
In [7]:
% Initialize matrix A and B
A = [1, 2, 4; 5, 3, 2]
B = [1, 3, 4; 1, 1, 1]
In [8]:
% Initialize constant s
s = 2
In [9]:
% See how element-wise addition works
add_AB = A + B
In [10]:
% See how element-wise subtraction works
sub_AB = A - B
In [11]:
% See how scalar multiplication works
mult_As = A * s
In [12]:
% Divide A by s
div_As = A / s
In [13]:
% What happens if we have a Matrix + scalar?
add_As = A + s
In [14]:
% Initialize matrix A
A = [1, 2, 3; 4, 5, 6;7, 8, 9]
In [15]:
% Initialize vector v
v = [1; 1; 1]
In [16]:
% Multiply A * v
Av = A * v
In [17]:
% Initialize a 3 by 2 matrix
A = [1, 2; 3, 4;5, 6]
In [18]:
% Initialize a 2 by 1 matrix
B = [1; 2]
In [19]:
% We expect a resulting matrix of (3 by 2)*(2 by 1) = (3 by 1)
mult_AB = A*B
In [20]:
% Initialize random matrices A and B
A = [1,2;4,5]
B = [1,1;0,2]
In [21]:
% Initialize a 2 by 2 identity matrix
I = eye(2)
% The above notation is the same as I = [1,0;0,1]
In [22]:
% What happens when we multiply I*A ?
IA = I*A
In [23]:
% How about A*I ?
AI = A*I
In [24]:
% Compute A*B
AB = A*B
In [25]:
% Is it equal to B*A?
BA = B*A
In [26]:
% Note that IA = AI but AB != BA
In [27]:
% Initialize matrix A
A = [1,2,0;0,5,6;7,0,9]
In [28]:
% Transpose A
A_trans = A'
In [29]:
% Take the inverse of A
A_inv = inv(A)
In [30]:
% What is A^(-1)*A?
A_invA = inv(A) * A
Effectively the identity matrix