In [2]:
A = [1, 2; 3, 4; 5, 6]
B = [11, 12; 13, 14; 15, 16]
C = [1 1; 2 2]
In [3]:
A * C
In [5]:
A .* B % Element wise multiply
In [6]:
A .^ 2 % element wise square
In [9]:
v = [1; 2; 3];
1 ./ v % element wise reciprocal
In [13]:
log(v)
exp(v)
abs(v)
-v
In [14]:
v + ones(length(v), 1)
In [15]:
v + 1
In [17]:
A' % Transpose
(A')'
In [25]:
a = [1 15 2 0.5]
In [27]:
val = max(a);
[val, ind] = max(a)
In [29]:
a < 3 % elemnt wise comparison
In [30]:
find(a < 3) % Find actual elements
In [31]:
A = magic(3) % All rows, cols and diagonals sum to same thing
In [33]:
[r, c] = find(A >= 7) % 1,1 - 3,2 - 2,3
In [37]:
sum(a)
prod(a) % product
floor(a)
ceil(a)
In [39]:
max(rand(3), rand(3)) % elementwise max of two matrixes
In [44]:
A
max(A, [], 1) % Column wise maximum
max(A, [], 2) % Row wise maximum
max(max(A)) % all max
In [46]:
A = magic(9)
In [47]:
sum(A, 1) % all the same
In [49]:
sum(A, 2) % all the same
In [52]:
A .* eye(9) % just diagonal elements
In [54]:
sum(sum(A .* eye(9))) % sum all these numbers
In [59]:
flipud(eye(9)) % flip vertically
In [60]:
A = magic(3)
In [62]:
A_inv = pinv(A) % inverse
In [64]:
A_inv * A % essentially the identity matrix
In [ ]: