I need to multiply two N x N Matrices... Ive seen some sample code on some websites, but they are too complex..any sugestons on a which is the best way to do it?.. any samples?
Printable View
I need to multiply two N x N Matrices... Ive seen some sample code on some websites, but they are too complex..any sugestons on a which is the best way to do it?.. any samples?
Go to http://mathworld.wolfram.com/MatrixMultiplication.html. In there you will find an algorithm for multiplying any two matrices that can be multiplied.
If you know to multiply 2 matrices mathematically, it shouldn't be too hard to put in in C/C++.
Very simple... ;)Code:#define N1 ...
#define N2 ...
#define M ...
int A[N1][M], B[M][N2], C[N1][N2];
for(int i=0; i<N1; i++)
{
for(int j=0; j<N2; j++)
{
C[i][j] = 0;
for(k=0; k<M; k++)
C[i][j] += A[i][k]*B[k][J];
}
}
yeah i agree with cilu mostly
but i prefer this way if i had got the chance:
regards,Code:const int M...
const int N...
const int MN...
jolley
If you don't feel like writing your own matrix classes, you might try TNT:
http://math.nist.gov/tnt/
I was trying to show how to multiply two matrices, not how to declare their sizes.Quote:
Originally Posted by jolley
oh..thanks for the links and thanks for the code guys!...I was looking for a simple code since the one I was writning was too complicated ..but now I get the idea ...I'lll be adding some more code to that to make it work the way I need... then I'll convert it to MIPS assembly...(thats why im looking for a simple code) once again.. thanks for you help guys! If you get any other ideas, please post.. thank you!.