We are given a sequence (chain) <A1, A2, ...... ,An> of n matrices to be multiplied, and we wish to compute the product
A1*A2* .... * An
One Nive Way is
We can evaluate the expression (15.5) using the standard algorithm for multiplying pairs of matrices as a subroutine once we have parenthesized it to resolve all
ambiguities in how the matrices are multiplied together.
Matrix multiplication is associative, and so all parenthesizations yield the same product. A product of matrices is fully parenthesized if it is either a single matrix or the product of two fully parenthesized matrix products, surrounded by parentheses. For example, if the chain of matrices is <A1, A2, A3, A4> then we can fully parenthesize the product
A1*A2*A3*A4 in five distinct ways:
How we parenthesize a chain of matrices can have a dramatic impact on the cost
of evaluating the product. Consider first the cost of multiplying two matrices.
So here is the Formula we will be used for solving our problem in an optimized way,
Of course we will be using dynamic programming and our approach will be as follow
1. Characterize the structure of an optimal solution.
2. Recursively define the value of an optimal solution.
3. Compute the value of an optimal solution
4. Construct an optimal solution from computed information.
MATRIX-MULTIPLY.A; B/ 1 if A:columns ¤ B:rows 2 error “incompatible dimensions” 3 else let C be a new A:rows B:columns matrix 4 for i D 1 to A:rows 5 for j D 1 to B:columns 6 cij D 0 7 for k D 1 to A:columns 8 cij D cij C aik bkj 9 return C
Comments