Jernej
Jernej

Reputation: 352

Computing the determinant of a C array

I have written a program that generates a few N x N matrices for which I would like to compute their determinant. Related to this I have two questions

Edit. If possible provide an example of computing the determinant for the recommended library.

Upvotes: 4

Views: 1934

Answers (3)

Dancrumb
Dancrumb

Reputation: 27539

As for Matrix Libraries, it looks like that question is answered here:

Recommendations for a small c-based vector and matrix library

As for casting to an integer: if the determinant is not an integer, then you shouldn't be casting it to an integer, you should be using round, floor, or ceil to convert it in an acceptable way. These will probably give you integral values, but you will still need to cast them; however, you will now be able to do so without fear of losing any information.

Upvotes: 4

deStrangis
deStrangis

Reputation: 1930

You have GSL, but the choice really depends on your matrices. Are the matrices dense or sparse? Is N big or small? For small Ns you may find that coding the determinant yourself using Cramer's rule or Gauss elimination is faster, since most hight performance libraries focus on big matrices and their optimisations may introduce overhead on simple problems.

Upvotes: 2

Aftnix
Aftnix

Reputation: 4589

You can work wonders with matrices by blas and lapack. They are actually written in fortran and using them from "c" is kind of a tweak. but all in all they can crunch numbers in horrendous speed.

http://www.netlib.org/lapack/lug/node11.html

Upvotes: 3

Related Questions