Jump to content
  • Advertisement
Sign in to follow this  
TheUnbeliever

Matrix Multiplication

This topic is 4324 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been trying to get a handle on this before actually applying it to 3D graphics, using WikiPedia to get the theory and then using this site to check my answers. I might just buy a maths textbook, as I normally find they're actually quite helpful, with the explanation, exercises and solutions in the one place. I'm only 15, so my school math isn't that far ahead (a fair bit of trigonometry (right angled, [co]sine rule[s], equations and identities), some algebra, plus a few bits that teachers have taught us as the top class), although I'm interested in maths and programming, so I've picked up a few small things along the way as they were helpful (some differentiation, a few obscure (to me) optimisations for specific problems). Anyway, WikiPedia lists the 'vector-lists method', and it seems like a reasonably elegant method to me. So, I'm trying to multiply the two matrices A and B:
A = [2 3   B = [1 5
     4 5        3 7]
     6 7]

A1 = [2    B1 = [1 5]
      3]

A2 = [4    B2 = [3 7]
      5]

A3 = [6
      7]

AB = [(A1B1) (A1B2)
      (A2B1) (A2B2)
      (A3B1) (A3B2)]

A1B1 = [2 10  A1B2 = [6 14
        3 15]         9 21]

A2B1 = [4 20  A2B2 = [12 28
        1 25]         15 35]

A3B1 = [6 30  A3B2 = [18 42
        7 35]         21 49]
Now, that all seems fine, until I realise that I now have 6 matrices which I somehow have to convert to scalars in order to get the 2x3 (col. x row.) matrix which I must finally get. What am I missing? Sorry if this is a bit of a 'n00b' question for this board. EDIT: Actually, after posting this, I vaguely remembered the determinant of a matrix associating a scalar value with n x n matrices. Applying this gives me:
A1B1 = [2 10  A1B2 = [6 14
        3 15]         9 27]
det(A1B1) = 2(10) - 10(3) = 0
det(A1B2) = 6(27) - 14(9) = 36

A2B1 = [4 20  A2B2 = [12 28
        1 25]         15 35]
det(A2B1) = 4(25) - 20(1) = 80
det(A2B2) = 12(35) - 28(15) = 0

A3B1 = [6 30  A3B2 = [18 42
        7 35]         21 49]
det(A3B1) = 6(35) - 30(7) = 0
det(A3B2) = 18(49) - 42(21) = 0
... Which, unfortunately, bears no semblance to the solution given me by the link I posted above. Got all excited for a minute there...

Share this post


Link to post
Share on other sites
Advertisement
Ah, so having gone back to relearn how to do the dot product of two vectors, I now get:


A = [2 3 B = [1 5
4 5 3 7]
6 7]

A1 = [2 B1 = [1 5]
3]

A2 = [4 B2 = [3 7]
5]

A3 = [6
7]

AB = [(A1B1) (A1B2)
(A2B1) (A2B2)
(A3B1) (A3B2)]

A1B1 = 17 A1B2 = 27
A2B1 = 29 A2B2 = 47
A3B1 = 41 A3B2 = 67

AB = [17 27
29 47
41 67]


Which seems okay to me... But the tool I linked to above gives

AB = [11 31
19 55
27 79]


And I really can't see where they're coming from...

Share this post


Link to post
Share on other sites
Because B1 = [1 3] and B2 = [5 7] (didn't notice until now).

You take rows from A and columns from B, not rows from both.

Share this post


Link to post
Share on other sites

A = [2 3 B = [1 5
4 5 3 7]
6 7]

A1 = [2 B1 = [1 3]
3]

A2 = [4 B2 = [5 7]
5]

A3 = [6
7]

AB = [(A1B1) (A1B2)
(A2B1) (A2B2)
(A3B1) (A3B2)]

A1B1 = 11 A1B2 = 31
A2B1 = 19 A2B2 = 55
A3B1 = 29 A3B2 = 79

AB = [11 31
19 55
29 79]


Great! Thanks, ToohrVyk. ++rating - fast response and both precise and accurate.

Share this post


Link to post
Share on other sites
It seems like you have the right idea, but I'm guessing you typoed one of the entries:

AB = [11 31
19 55
27 79]

Don't worry if this seems like a lot of work for a small result. You won't have to reduce A and B into 2x1/1x2 matrices once you get the hang of it. 'To find entry [i,j], run along the ith row of A and the jth column of B, summing the pointwise products'. As complicated as the statement sounds, it's the sort of thing you'll be doing in your sleep after a little practice, so that you can multiply a 12x9 matrix with a 9x10 without having to write down any workings.

Regards
Admiral

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!