Search code examples
c++equationalgebrasparse-matrix

sparse matrix overdetermined linear equation system c/c++ library


I need a library to solve Ax=b systems, where A is a non-symmetric sparse matrix, with 8 entry per row (and it might be quite big). I think a library that implements biconjugate gradient should be fine, but i can't find one that works (i've tried iml++, but there are some headers missing in the iml++/sparselib++ packages). Any tips?


Solution

  • There are standard ways of treating overdetermined systems. For example Wikipedia says this:

    A set of linear simultaneous equations can be written in matrix form as Ax = y. If there are more equations than variables, the system is called overdetermined, and has (in general) no solutions. The system can then be changed to (ATA)x = ATy. The new system has as many equations as variables (the matrix ATA is a square matrix) and can be solved in the usual way. The solution is a least-squares solution of the original, overdetermined system, minimizing the Euclidean norm ||Ax − y||, a measure of the discrepancy between the two sides in the original system.

    Therefore you can use any standard square matrix sparse solver.

    Personally I use a direct solver from CSparse by Tim Davis. Tim has written a number of excellent direct sparse solvers. Indeed, his UMFPACK is another excellent option and is used by MATLAB, for example. Note that both of these solvers offer C interfaces. If you are looking for something with a native C++ interface then I have nothing to offer.

    I have had some experience with iterative solvers. However, I have found that for the problems I was looking at, the iterative methods became unstable for large matrices. I have had much more success with direct solvers. Of course, it's perfectly plausible that you could have the reverse experience depending on the type of matrix your problem throws up.