3x3 by 3x2 Matrix Multiplication?

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 :)?

Last edited on
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:

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
You would not need 3 loops unless you had a 3D array... 2 loops for a 2D array (matrix)
@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 . :-)
Oh crap I forgot you're doing the dot product.
Topic archived. No new replies allowed.