3x3 by 3x2 Matrix Multiplication?

Mar 19, 2011 at 8:45am
Hey guys, I'm working on a little project and I need to do a 3x3 by a 3x2 (3 rows, 2 columns) matrix.

I've worked out that I'm going to need 3 for loops, but I can't figure it out past that, can someone help please :)?

Thanks!
Last edited on Mar 19, 2011 at 8:45am
Mar 19, 2011 at 9:02am
1. Create the arrays on the stack (including the 3x2 resulting matrix)
2. Read in the arrays (from file, console, etc)
3. For each row vector in the 3x3 matrix (first loop), and each column vector in the 3x2 matrix (second loop), compute the dot product. This is done by simply multiplying the corresponding components and adding those products together (third loop).

This is only to give you some algorithmic direction. Consult wiki for examples:
http://en.wikipedia.org/wiki/Matrix_multiplication

Regards
Mar 19, 2011 at 7:06pm
Great post by simeonz. My advice is to try to translate the formula http://en.wikipedia.org/wiki/Matrix_multiplication (shown on the "Technical Details" part), into code, which shouldnt be too hard :-)

BTW: There are gazillions of matrix multiplication implementations on c++ . This should be helpful http://www.edcc.edu/faculty/paul.bladek/Cmpsc142/matmult.htm
Last edited on Mar 19, 2011 at 7:07pm
Mar 19, 2011 at 11:47pm
You would not need 3 loops unless you had a 3D array... 2 loops for a 2D array (matrix)
Mar 21, 2011 at 4:24pm
@benjelly: Actually you DO need 3 loops. Each element i,j of the product matrix is the scalar product of row * column. To do the scalar product, you need 1 loop, and 2 extra loops to run through each i,j element . :-)
Mar 21, 2011 at 4:47pm
Oh crap I forgot you're doing the dot product.
Topic archived. No new replies allowed.