i need some help here.
ive got a 2d array (vector<vector<double>> v), and i need to find the determinant. im at work, and i have to convert an old matlab program over, but im run into this little problem...ive been googling and i havent found a good definition of what it is. can someone help me out?
Go to www.gamedev.net and read their articles and resources concerning matrices and quaternions - I think its in the math and physics section.
They have several articles about the determinant and sample code that will find the determinant of a matrix.
ok, im reading it, alot of it is going way over my head. right now im tringt o sort out the 2d array (which i guess is a matrix), in my other thread.
ok, i get how to multply them to get one. but i have a question.
If you scroll down to where he multplies and has that huge 4 chunk matrix, are those multplied together or added together to produce the final matrix?
Multiplied. You concatenate matrices by multiplying them together.
Matrix Matrix_Multiply(Matrix mat1, Matrix mat2)
int i, j, k;
// For speed reasons, use the unroll-loops option of your
for(i = 0; i < 4; i++)
for(j = 0; j < 4; j++)
for(k = 0, mat[i][j] = 0; k < 4; k++)
mat[i][j] += mat1[i][k] * mat2[k][j];
I would first try this outside of the vector STL. Use a standard 2D array and attempt to find its determinant. Then when you fully understand it, use the STL. Personally, I'd stick with what is straightforward and not worry about all the razzamatazz of the STL. There are times to use it and it is a great tool, but this is not one of those times.
Also I would not recommend returning a matrix as this can get confusing. If you know the data type of your matrices then there is really no reason to make the function work with all data types - unless you are coding an abstract generic matrix class that has a determinant function. I'm not sure why he (the author) is creating a matrix object but remember its only one approach to the problem.
If you do not like the 2D array because of the inherent multiplies to fetch elements and set elements, turn the 2D array into a 1D array like the author states.