Closed ghost closed 10 years ago
Nope, the multiplication and the indices are correct. v is a column vector, M is column major (i.e. the first index designates the matrix column). When multiplying a column vector with a matrix the resulting vector is achieved by transposing the column vector into a row vector and by taking the inner product with each of the matrices rows.
If you ran into an issue using that function, then this is because you're having your matrix accidently in row major ordering. Note that when writing out a matrix in C, be it a simple or a multidimensional array, the columns are what on the screen looks like rows and vice versa. Naively one may suggest "hey make it look right in the code", but that's the wrong approach, because it has to be correct mathematically. And mathematically we need to access matrix column vectors more often than row vectors, hence the elements in a vector are to be consecutive in memory which makes them look "transposed" in the source code.
I believe Line 184:
r[j] += M[i][j] * v[i];
Should be:
r[j] += M[j][i] * v[i];