Click to See Complete Forum and Search --> : function for determinant of matrix?


lisa188
July 15th, 2002, 04:51 PM
is there a c++ function to take the determinant of a matrix (represented by a 2-D array)?

NigelQ
July 15th, 2002, 05:05 PM
DirectX has a call named D3DXMatrixfDeterminant - I've never used it, don't know what it does and don't know whether it would be of use to you, but I know it's there.:D

Hope this helps,

- Nigel

NigelQ
July 15th, 2002, 05:09 PM
Or roll your own routine (http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=540&lngWId=3)

Hope this helps,

- Nigel

Bob Davis
July 16th, 2002, 12:00 PM
Nigel's routine looks great for a 3x3 matrix. Do you know what dimensions of matrices you will need to pass to the function? For example, there is a simple formula for the determinant of a 2x2 matrix if you need that, or you can use the 3x3 function that Nigel linked to. The problem is, as the matrix grows, it becomes exponentially harder to calculate the determinant. I'm not sure how high-level math packages like Maple or Matlab do it, but the easiest way I can think of is to reduce the matrix into upper triangular form, then multiply across the diagonal, and then make the appropriate changes. There's probably a better way, though; a Google search may yield a better algorithm.