Search code examples
c++mathlinear-algebraequation-solvinglinear-equation

How to invert a matrix


I need to solve a system of n-linear equations with n-unknown variables in C++ using the gaussian method of elimnation. Any hints how to achieve that? I'll be probably using rand(); for the amount of n, since isn't available, because C++11 I can't use.


Solution

  • to solve a linear system

    AX=B

    you need to invert a matrix A, which results in A^(-1) and multiply A^(-1) * B to obtain X. This is the example code to invert non-singular matrix using Gauss - Jordan elimination algorithm (complexity is O(n^3)):

    matrix inversion using Gauss-Jordan elimination