Page 42 - A Guide to MATLAB for Beginners and Experienced Users
P. 42
Vectors and Matrices 23
Matrices
A matrix is a rectangular array of numbers. Row and column vectors, which
we discussed above, are examples of matrices. Consider the 3 × 4 matrix
1 2 3 4
A = 5 6 7 8 .
9101112
It can be entered in MATLAB withthe command
>> A = [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12]
A=
1 2 3 4
5 6 7 8
9 10 11 12
Note that the matrix elements in any row are separated by commas, and the
rows are separated by semicolons. The elements in a row can also be separated
by spaces.
If two matrices A and B are the same size, their (element-by-element) sum
is obtained by typing A+B. You can also add a scalar (a single number) to a
matrix; A+c adds c to eachelement in A. Likewise, A-B represents the
difference of A and B, and A-c subtracts the number c from eachelement
of A.If A and B are multiplicatively compatible (that is, if A is n × m and B is
m× ), then their product A*B is n × . Recall that the element of A*B in the
ithrow and jth column is the sum of the products of the elements from the
ithrow of A times the elements from the jthcolumn of B, that is,
m
(A ∗ B) ij = A ik B kj , 1 ≤ i ≤ n, 1 ≤ j ≤ .
k=1
The product of a number c and the matrix A is given by c*A, and A’ represents
the conjugate transpose of A. (For more information, see the online help for
ctranspose and transpose.)
A simple illustration is given by the matrix product of the 3 × 4 matrix A
above by the 4 × 1 column vector Z’:
>> A*Z’
ans =
60
140
220