| Mathematics | ![]() |
Matrix Multiplication
Multiplication of matrices is defined in a way that reflects composition of the underlying linear transformations and allows compact representation of systems of simultaneous linear equations. The matrix product C = AB is defined when the column dimension of A is equal to the row dimension of B, or when one of them is a scalar. If A is m-by-p and B is p-by-n, their product C is m-by-n. The product can actually be defined using MATLAB's for loops, colon notation, and vector dot products.
for i = 1:m
for j = 1:n
C(i,j) = A(i,:)*B(:,j);
end
end
MATLAB uses a single asterisk to denote matrix multiplication. The next two examples illustrate the fact that matrix multiplication is not commutative; AB is usually not equal to BA.
X = A*B
X =
15 15 15
26 38 26
41 70 39
Y = B*A
Y =
15 28 47
15 34 60
15 28 43
A matrix can be multiplied on the right by a column vector and on the left by a row vector.
x = A*u
x =
8
17
30
y = v*B
y =
12 -7 10
Rectangular matrix multiplications must satisfy the dimension compatibility conditions.
X = A*C
X =
17 19
31 41
51 70
Y = C*A
Error using ==> *
Inner matrix dimensions must agree.
Anything can be multiplied by a scalar.
w = s*v
w =
14 0 -7
| Vector Products and Transpose | The Identity Matrix | ![]() |