I'm using an inverse function that hasn't been tested that thoroughly, but the product of this matrix and A does appear to be I. I didn't look at the code, but this particular algorithm can be somewhat difficult to debug :-) The one thing I'd suggest is to get a hold of an implementation you can be confident works, so you have something to compare your results to.

Share this post

Link to post

Share on other sites

You mean the gaussian elimination algorithm where you transform the matrix to identity and vice versa with identity to inv(A).

You could could transform the matrix to top triangle matrix and get the determinant as the product of the diagonal elements, I ll probably implement this as well. flInvDet = 1/det . I ll play around with it

0

Share this post

Link to post

Share on other sites

My determinant calculation was wrong, the way I implemented it works for 3x3 matrices only (you know where you add up the product of the diagonals from top left to bottom rightand subtract the products of the diagonals bottom left to top right)

Do you know if there s an algorithm that does not have to store the indices of the minor matrices upon recursive calculation? For an arbitrary size square matrix?

0

Share this post

Link to post

Share on other sites

note - the way you calculated the determinant (3 diagonals minus 3 diagonals) is more simple to a human but is more calculations than necessary. There are a total of 18 multiplications and 6 additions in your method and 9 multiplications and 6 additions in the "regular" (recursivly calc det of minors) method for 3x3 matrix.

Even the "regular" method is too slow for large matrices - it is order O(n!) which is horrible for big "n". There is faster algorithm using LU decomposition (order O(n^3)) and maybe there are even faster methods I am not aware of. Perhaps for matrices of size 3x3 or 4x4 the regular method is faster.

The same goes for the algorithm you are using to inverse -it is simple for humans, but is more calculations than necessary and is less stable (numerical errors are big).

If I am not mistaken, the "proper" way to inverse a matrix of arbitary size is by LU or LDU decomposition. These methods are faster (only 20% of the operations of the "human" method - gauss elimination) and are more numericaly stable (less dividing by small numbers). Again, perhaps for small matrices gaussian elimination is faster, I am not sure, but remember stability is sometimes more important than speed (what good is fast calc if you have big errors?).

PS. LU means writing the matrix A as L*U where L is lower triangular matrix and U is upper triangular; LDU is lower unit matrix times diagonal times upper unit matrix. The algorithm to do that is not hard and once you do that calculating the determinant or inversing is simple.

These are methods you dont learn in Linear Algebra because they are wierder than the ordinary inverse algorithm and are harder to explain, but you learn them in numerical analysis or such courses (where you learn to do efficient math on a computer).

sorry I cant help anymore...

0

Share this post

Link to post

Share on other sites

This topic is 4197 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.