Not Yet Answered # How to caculate Inverted matrix(array) (A)-1 in C++

mike_2000_17 2,669 DavidB 44 Discussion Starter hana.shamsaldeen OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...

1

I would find Inverted matrix A ... (A)-1

Like you would in any other language that don't have built-in methods to do so. There are many algorithms for this purpose, each with different properties (efficiency, stability, amplification of round-off errors, etc.) and for different kinds of matrices (general, normal, well-conditioned / ill-conditioned, symmetric, positive-/negative-definite, indefinite, rank-deficient (pseudo-inverse methods), etc.). By and large, however, inverting a matrix is rarely needed, so most methods are essentially methods to solve a system of linear equations (Ax = b), and by making the right-hand side equal to the identity matrix, you find the inverse (if that is really what you need). So, what you need to look for are methods to solve systems of linear equations. These include, but not limited to, Gaussian elimination (or its more sophisticated versions, the LU-decomposition or Cholesky decomposition (symmetric positive-definite)), QR decomposition (and variations like QL, RQ, and RRQR), Singular-value decomposition, etc... and the list goes on. There are entire books written on the subject, for example Golub and van Loan (this is pretty much the bible of matrix numerical methods).

There are also libraries that can do that for you, like Eigen, or my own, or the older classic (C) libraries like LAPACK or GSL.

0

What, exactly, are you looking for? An explanation of an algorithm for doing the inversion?

Help writing code for an algorithm you have?

Or perhaps you don't need the program (source code) itself, you just need a tool that does the inversion? In this case, most scientific calculators have that function built-in.

Otherwise, Mike has listed several pretty good resources to get you started reading about the process.

0

yes , I'm looking for An explanation of an algorithm for doing the inversion

but thanks , I found it:::

```
int main()
{
float a[3][3]={2 ,0 , 0 ,0 ,1 ,0 ,0 ,0 ,5};
float b[3][3]={1 ,0 , 0 ,0 ,1 ,0 ,0 ,0 ,1};
int i,j,k,l;
float t;
for (j = 0; j<4; j++)
{
for (i=j; i<4; i++)
{
if (a[i][j] != 0)
{
t = 1.0/a[j][j];
for (k = 0; k<8; k++)
{
a[j][k] *= t;
b[j][k] *= t;
}
for (l = 0; l<4; l++)
{
if (l != j)
{
t = -a[l][j];
for (k = 0; k<4; k++)
{
a[l][k] = a[l][k] + t*a[j][k];
b[l][k] = b[l][k] + t*b[j][k];
}
}
}
}
}
}
}
```

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

I don’t want at this stage work on a big separate project as I've already got plenty ...

Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.

btn_addline :

`Private Sub btn_addline_Click(ByVal ...`