Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Possible Duplicate:
Matrix multiplications (obtaining values)

Hi,

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|improve this question

migrated from stackoverflow.com 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 has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

1 Answer 1

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|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 A*B*C = 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 A*B = 3X5 = 15 A*B*C = 3X7 = 21 A*B*C*D = 3X2 if i add them up i get 42, so not good, then i tried A*B = 3X4X5 = 60 and A*B*C = 3X5X7 = 105 when i add them i get 165 but now i cant get 110 :( –  Anonymous May 2 '11 at 0:10