C++ Eigen Library

C++ Eigen Library

本文关键字:Library Eigen C++      更新时间:2023-10-16

我很难用#include编译该程序。我看到,如果我评论这一行,它会编译。

matrixxd a =(1.0/(double(d( *(p * u * p.p.transpose(( - (p * u( *(p * u(.transpose((.transpose(((。inverse((;

我无法更改标头,因为我需要在ROS中运行此代码,并且必须使用内部构建的特征库。我正在使用此链接中所述的代码
如何在一组2D点上安装边界椭圆。
任何帮助都大大应用了。

   pound include iostream   
   pound include Eigen/Dense  
   using namespace std;  
   using Eigen::MatrixXd;  
   int main ( )  
   {  
    //The tolerance for error in fitting the ellipse
    double tolerance = 0.2;
    int n = 12; // number of points
    int d = 2; // dimension
    MatrixXd p(d,n); //Fill matrix with random points
    p(0,0) = -2.644722; 
    p(0,1) = -2.644961;
    p(0,2) = -2.647504;
    p(0,3) = -2.652942;
    p(0,4) = -2.652745;
    p(0,5) = -2.649508;
    p(0,6) = -2.651345;
    p(0,7) = -2.654530;
    p(0,8) = -2.651370;
    p(0,9) = -2.653966;
    p(0,10) = -2.661322;
    p(0,11) = -2.648208;
    p(1,0) = 4.764553; 
    p(1,1) = 4.718605;
    p(1,2) = 4.676985;
    p(1,3) = 4.640509;
    p(1,4) = 4.595640;
    p(1,5) = 4.546657;
    p(1,6) = 4.506177;
    p(1,7) = 4.468277;
    p(1,8) = 4.421263;
    p(1,9) = 4.383508;
    p(1,10) = 4.353276;
    p(1,11) = 4.293307;

    cout << p << endl; 
    MatrixXd q = p;
    q.conservativeResize(p.rows() + 1, p.cols());
    for(size_t i = 0; i < q.cols(); i++)
    {
        q(q.rows() - 1, i) = 1;
    }
    int count = 1;
    double err = 1;
    const double init_u = 1.0 / (double) n;
    MatrixXd u = MatrixXd::Constant(n, 1, init_u);

    while(err > tolerance)
    {
        MatrixXd Q_tr = q.transpose();
        cout << "1 " << endl;
        MatrixXd X = q * u.asDiagonal() * Q_tr;
        cout << "1a " << endl;
        MatrixXd M = (Q_tr * X.inverse() * q).diagonal();
        cout << "1b " << endl;

        int j_x, j_y;
        double maximum = M.maxCoeff(&j_x, &j_y);
        double step_size = (maximum - d - 1) / ((d + 1) * (maximum + 1));
        MatrixXd new_u = (1 - step_size) * u;
        new_u(j_x, 0) += step_size;
        cout << "2 " << endl;
        //Find err
        MatrixXd u_diff = new_u - u;
        for(size_t i = 0; i < u_diff.rows(); i++)
        {
         for(size_t j = 0; j < u_diff.cols(); j++)
                u_diff(i, j) *= u_diff(i, j); // Square each element of the            matrix
        }
        err = sqrt(u_diff.sum());
        count++;
        u = new_u;
    }
    cout << "3 " << endl;
    MatrixXd U = u.asDiagonal();
    MatrixXd A = (1.0 / (double) d) * (p * U * p.transpose() - (p * u) * (p * u).transpose()).inverse();
    MatrixXd c = p * u;
   cout << A << endl;
   cout << c << endl;
    return 0; 
}

如果我用

替换了明显的 pound include bogus
#include <iostream>
#include <Eigen/Dense>

它可以很好地编译。它还运行,打印一些数字并返回0。