Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Matrix multiplications (obtaining values)


I have a final tomorrow and it includes multiplying matrices (getting a table of values) but i do not understand how he is getting some of the numbers

something like this

suppose the matrices are

 A3X4  B4X5    C5x7    D7X2

in the results table he has

          A    B     C       D
    A     0    60    165     134
    B           0    140     110
    C                0       70
    D                        0

     A     B      C      D
A    A     A*B    A*B*C  A*B*C*D
B          B      B*C    B*C*D
C                 C      C*D
D                        D

How is he getting 164 unders C for example? I know how he is getting the twi dimentional ones like for instance the 140 under C would be B*C which is 4X5X7 = 140 but I have no idea how he is getting for the A*B*C = 165

Thank you

share|cite|improve this question

migrated from May 2 '11 at 0:22

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Qiaochu Yuan May 2 '11 at 0:27

This question was marked as an exact duplicate of an existing question.

It looks to me as if the table contains operation counts. For example AB requires 3*5 dot products, each requiring 4 ops and so AB requires 60 ops in total. I reckon the table is showing the least op count way to compute ABCD, ie A*(B*(CD); 70 ops for CD (5x7 * 7x2) an additional 40 to compute B*(CD) (4x5 * 5x2) and finally an additional 24 to compute A*(B*(C*D)) (3x4 * 4x2). – dmuir May 13 '11 at 14:24

If you're multiplying E = A*B*C*D, then E ought to be a 3x2 matrix, right?

And the rule for matrix multiplication is simple:

Given W(m,n), U(m, p), and V(p, n) then W = U*V

for (int i = 0; i < m; ++i)
    for (int j = 0; j < n; ++j)
        double sum = 0.0;
        for (int k = 0; k < p; k++)
            sum += u[i, k]*v{k, j];   
        w[i, j] = sum;
share|cite|improve this answer
I know what you say, I know that 3 matrices that are for example A3X4, B4X5, C5X7, would give me a 3X7, but thats not what i need... what i need to know is the number of multiplications..i think thats what that value means,,, in example above i need to figure out how to get ABC = 165 considering A = 3X4, B=4x5, C=5X7 – Anonymous May 1 '11 at 23:47
Yes, you have to calculate A*B, then multiply that by C, then multiply that by D. – duffymo May 1 '11 at 23:57
Ok so, i did AB = 3X5 = 15 ABC = 3X7 = 21 ABCD = 3X2 if i add them up i get 42, so not good, then i tried AB = 3X4X5 = 60 and AB*C = 3X5X7 = 105 when i add them i get 165 but now i cant get 110 :( – Anonymous May 2 '11 at 0:10