Problem: Find the possibility of minimum multiplication from the Matrixes (W.X.Y.Z) using the Matrix Chain Multiplication method. W(8x9).X(9x5).Y(5x12).Z(12x16) code example

Example: matrix chain multiplication

minimum_multiplication(n: integer; d: array(0..n))
        M: array(1..n, 1..n) := (others => 0);

        for diagonal in 1 .. n-1 loop 
            for i in 1 .. n - diagonal loop 
                j := i + diagonal;

                min := integer'last;
                for k in i .. j-1 loop
                    current := M[i, k] + M[k+1, j] + d(i-1)*d(k)*d(j) 
                    if current < min then
                        min := current
                    end if
                end loop
                M[i, j] := min
            end loop
        end loop

Tags:

Misc Example