

A simple example will demonstrate this fact: If we write the product AB in terms of the dimensions, as (m x p )(p x q) = m x q, we can easily determine the dimensions of the product by “canceling” the inner dimensions (here p), which must be equal for the product to be defined. Matrix multiplication does not have the commutative property that is, in general, AB =I BA. Each element in the with row of A is multiplied by the corresponding element in the with column of B. The sum of the products is the element cij. The algorithm defined by (2.4-5) is easy to remember. The product has the same number of rows s A and the same number of columns as B. . For the product to be defined, the matrices A and B must be conformable that is, the number of rows in B must equal the number of columns in A. We can state the general result for matrix multiplication as follows: Suppose A has dimension m x p and B has dimension p x q, If C is the product AB, then C has dimension m x q and its elements are given byįor all i = 1, 2, …, m and j = 1, 2, …, q. Thus if we were to type [3, I, 7) * [ 4, 6, 5) in MATLAB, we would receive an error message. The following product is defined in matrix multiplication and gives the result shown:
MATLAB MATRIX HOW TO
The following MATLAB session shows how to perform the matrix multiplication shown in (2.4-4).Įlement-by-element multiplication is defined for the following product: = However, this product is not defined for matrix multiplication, because the first matrix has three columns, but the second matrix does not have three rows. Use the operator * to perform matrix multiplication in MATLAB. The product AB” has the same number of rows as A and the same number of columns as B. The number of columns in A must equal the number of rows in B. The row-column multiplications form column vectors, and these-column vectors form the matrix result. We can expand this definition of multiplication to include the product of two matrices AB. In general, the product Ax, where A has p columns, is defined only if x has p rows. If A has m rows x is a column vector, the result of Ax is a column vector with m rows Note that the definition of multiplication requires that the number of columns in the matrix be equal to the number of rows in the vector. Thus the result of multiplying a 2 x 2 matrix times a 2 x 1 vector is a 2 x 1 array that is, a column vector. The scalar result of each row-column multiplication forms an element in the result, which is a column vector: by a matrix, think of the matrix as being composed of row vectors.

To generalize the preceding multiplication to a column vector multiplied. Thus the result of multiplying a 1 x n vector times an n x 1 vector is a 1 x 1 array, that is, a scalar. This definition applies to vectors having any number of elements, as long as both vectors have the same number of elements. Thus the result of multiplying a 1 x 3 vector times a 3 x 1 vector is a 1 x 1 array that is, a scalar. The matrix product of a row vector u with a column vector W is “defined in the same way as the vector dot product the tesult is a scalar that is the sum of the products of the corresponding vector elements that is, ‘Thus the vector dot product can be expressed in terms of unit vectors asĬarrying out the multiplication algebraically and using the properties given by If the vectors are perpendicular, e = 90° and thus u. Thus if the vectors are parallel and in the same direction, e = 0 and u. It can be computed from cos e, where e is the angle between the two vectors and, are. the magnitudes of the vectors. w of the vectors u and w is a scalar and can be thought of as the perpendicular projection of u onto w.

Thus matrix multiplication and division procedures apply to vectors as well, and we will introduce matrix multiplication by considering the vector case first. The vector dot product u. Recall that vectors are simply matrices with one row or one column. However, matrix multiplication and division are not the same as element-by-element multiplication and division. The corresponding matrix elements are summed or subtracted. Matrix addition and subtraction are identical to element-by-element addition and subtraction.
