Inverse matrix using own

I learned how to find the inverse matrix using Eigen . But when I find the return array, which is the output of the function, I got an error

query for the element 'inverse in' x, which is a non-class type of "Double **

Please help me using the C ++ library to find the inverse matrix.

The code I wrote is:

#include <iostream>
#include <armadillo>
#include <cmath>
#include <Eigen/Dense>

using namespace std;
using namespace arma;
using namespace Eigen;

int main()
{
    vec a;
    double ** x;

    double ** inv_x;
    a <<0 << 1 << 2 << 3 << 4; //input vector to function
    double ** f (vec a); //function declaration

    x= f(a);   // function call

    //inv_x=inv(x);

    cout << "The inverse of x is:\n" << x.inverse() << endl; // eigen command to find inverse
    return 0;
}

// function definition 
double ** f(vec a)
{
    double ** b = 0;
    int h=5;

    for(int i1=0;i1<h;i1++)
    {
         b[i1] = new double[h];
         {
            b[i1][0]=1;
            b[i1][1]=a[i1];
            b[i1][2]=a[i1]*a[i1]+1/12;
            b[i1][3]=pow(a[i1],3)+a[i1]/4;
            b[i1][4]=1/80+pow(a[i1],2)/2+pow(a[i1],4);
        }

    }
    return b;
}

Here the user-defined function freturns an array x. I am trying to find the inverse xusing my own library.

+4
source share
1 answer

-, , double ** , , .

Eigen::Map, Eigen, . :

double data[2][2];
Eigen::Map<Matrix<double,2,2,RowMajor> > mat(data[0]);
mat = mat.inverse();
+3

All Articles