Gauss Elimination for NxM matrix

后端 未结 3 487
半阙折子戏
半阙折子戏 2021-02-02 04:29
/* Program to demonstrate gaussian elimination
   on a set of linear simultaneous equations
 */

#include 

        
3条回答
  •  猫巷女王i
    2021-02-02 05:31

    1. (optional) Understand this. Do some examples on paper.
    2. Don't write code for Gaussian elimination yourself. Without some care, the naive gauss pivoting is unstable. You have to scale the lines and take care of pivoting with the greatest element, a starting point is there. Note that this advice holds for most linear algebra algorithms.
    3. If you want to solve systems of equations, LU decomposition, QR decomposition (stabler than LU, but slower), Cholesky decomposition (in the case the system is symmetric) or SVD (in the case the system is not square) are almost always better choices. Gaussian elimination is best for computing determinants however.
    4. Use the algorithms from LAPACK for the problems which need Gaussian elimination (eg. solving systems, or computing determinants). Really. Don't roll your own. Since you are doing C++, you may be interested in Armadillo which takes care of a lot of things for you.
    5. If you must roll your own for pedagogical reasons, have a look first at Numerical Recipes, version 3. Version 2 can be found online for free if you're low on budget / have no access to a library.
    6. As a general advice, don't code algorithms you don't understand.

提交回复
热议问题