This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Inverse dynamic matrix with Eigen 2

Tags: None
(comma "," separated)
hazemkrichene
Registered Member
Posts
7
Karma
0

Inverse dynamic matrix with Eigen 2

Mon Dec 18, 2017 10:40 am
Dear All,

I'm very new in Eigen. I installed Eigen 2 (i have problems with Eigen 3). What i need is to invert matrix of different sizes (NxN, where N between 5 and 100). For small size N < 5, it is very easy to use Matrix.inverse as follows:

Code: Select all
   int const nrow = 3;
   int const ncol = 3;
   Matrix<double, nrow, ncol > m;
   m << 10, 2, 3,
   4, 5, 6,
   7, 8, 9;
   Matrix<double, nrow, ncol > m1;
   m1 = m.inverse();


When N is more than 4, i get a lot of errors! I think that i need some decomposition technique. However, i'm not finding any documentation for Eigen 2, and i don't now how to do.

PS: For Eigen 3, only matrix initialization works for me. Any arithmetic operation generates an infinite number of errors.

Any help please?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You need to #include <Eigen/LU> for matrix inversion. Eigen3 should work, if not please copy-paste the first errors to get help !
hazemkrichene
Registered Member
Posts
7
Karma
0
Sorry, i did not mention the whole code. So i put already the Eigen/LU as you can see bellow:

Code: Select all
#include <iostream>
#include <Eigen/LU>

using namespace Eigen;
using Eigen::MatrixXd;

   int const nrow = 6;
   int const ncol = 6;
   Matrix<double, nrow, ncol> m;
   m << 10, 2, 3,10, 2, 3,
   4, 5, 6,4, 5, 6,
   4, 5, 8,4, 9, 6,
   4, 5, 8,4, 9, 16,
   4, 15, 8,4, 9, 6,
   7, 8, 9,7, 8, 20;
   Matrix<double, nrow, ncol> m1;
   m1 = m.inverse();
   std::cout << "Now v =\n" << m1 << std::endl;



I get the following errors:

Description Resource Path Location Type
[ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ] My_ERGM line 188, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\MapBase.h C/C++ Problem
[ skipping 3 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ] My_ERGM line 151, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\CwiseBinaryOp.h C/C++ Problem
[ skipping 5 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ] My_ERGM line 408, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\Matrix.h C/C++ Problem
required from 'bool Eigen::LU<MatrixType>::solve(const Eigen::MatrixBase<OtherDerived>&, ResultType*) const [with OtherDerived = Eigen::CwiseNullaryOp<Eigen::ei_scalar_identity_op<double>, Eigen::Matrix<double, 6, 6> >; ResultType = Eigen::Matrix<double, 6, 6>; MatrixType = Eigen::Matrix<double, 6, 6>]' My_ERGM line 499, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\LU\LU.h C/C++ Problem
required from 'bool Eigen::LU<MatrixType>::solve(const Eigen::MatrixBase<OtherDerived>&, ResultType*) const [with OtherDerived = Eigen::CwiseNullaryOp<Eigen::ei_scalar_identity_op<double>, Eigen::Matrix<double, 6, 6> >; ResultType = Eigen::Matrix<double, 6, 6>; MatrixType = Eigen::Matrix<double, 6, 6>]' My_ERGM line 505, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\LU\LU.h C/C++ Problem
required from 'const Eigen::CwiseBinaryOp<Eigen::ei_scalar_difference_op<typename Eigen::ei_traits<T>::Scalar>, Derived, OtherDerived> Eigen::MatrixBase<Derived>::operator-(const Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived = Eigen::Product<const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, 0>; Derived = Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 0, 32>; typename Eigen::ei_traits<T>::Scalar = double]' My_ERGM line 80, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\CwiseBinaryOp.h C/C++ Problem
required from 'const PlainMatrixType Eigen::MatrixBase<Derived>::inverse() const [with Derived = Eigen::Matrix<double, 6, 6>; Eigen::MatrixBase<Derived>::PlainMatrixType = Eigen::Matrix<double, 6, 6>]' My_ERGM line 319, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\LU\Inverse.h C/C++ Problem
required from 'Derived& Eigen::MatrixBase<Derived>::lazyAssign(const Eigen::MatrixBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<double, 10000, 10000, 2, 6, 6>; Derived = Eigen::Matrix<double, 10000, 10000, 2, 6, 6>]' My_ERGM line 432, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\Assign.h C/C++ Problem
required from 'Derived& Eigen::MatrixBase<Derived>::lazyAssign(const Eigen::MatrixBase<OtherDerived>&) [with OtherDerived = Eigen::Product<const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, 0>; Derived = Eigen::Matrix<double, 10000, 10000, 2, 6, 6>]' My_ERGM line 432, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\Assign.h C/C++ Problem
required from 'Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::CwiseBinaryOp(const Lhs&, const Rhs&, const BinaryOp&) [with BinaryOp = Eigen::ei_scalar_difference_op<double>; Lhs = Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 0, 32>; Rhs = Eigen::Product<const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, 0>]' My_ERGM line 90, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\CwiseBinaryOp.h C/C++ Problem
required from 'Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>&) [with _Scalar = double; int _Rows = 10000; int _Cols = 10000; int _Options = 2; int _MaxRows = 6; int _MaxCols = 6]' My_ERGM line 415, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\Matrix.h C/C++ Problem
required from 'Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const Eigen::MatrixBase<OtherDerived>&) [with OtherDerived = Eigen::Product<const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, 0>; _Scalar = double; int _Rows = 10000; int _Cols = 10000; int _Options = 2; int _MaxRows = 6; int _MaxCols = 6]' My_ERGM line 408, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\Matrix.h C/C++ Problem
required from 'Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::_set_noalias(const Eigen::MatrixBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<double, 10000, 10000, 2, 6, 6>; _Scalar = double; int _Rows = 10000; int _Cols = 10000; int _Options = 2; int _MaxRows = 6; int _MaxCols = 6]' My_ERGM line 554, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\Matrix.h C/C++ Problem
required from 'Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::_set_noalias(const Eigen::MatrixBase<OtherDerived>&) [with OtherDerived = Eigen::Product<const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, 0>; _Scalar = double; int _Rows = 10000; int _Cols = 10000; int _Options = 2; int _MaxRows = 6; int _MaxCols = 6]' My_ERGM line 554, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\Matrix.h C/C++ Problem
required from 'static Derived& Eigen::ei_assign_selector<Derived, OtherDerived, false, false>::run(Derived&, const OtherDerived&) [with Derived = Eigen::Matrix<double, 10000, 10000, 2, 6, 6>; OtherDerived = Eigen::Matrix<double, 10000, 10000, 2, 6, 6>]' My_ERGM line 447, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\Assign.h C/C++ Problem
required from 'static Derived& Eigen::ei_assign_selector<Derived, OtherDerived, false, false>::run(Derived&, const OtherDerived&) [with Derived = Eigen::Matrix<double, 10000, 10000, 2, 6, 6>; OtherDerived = Eigen::Product<const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, 0>]' My_ERGM line 447, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\Assign.h C/C++ Problem
required from 'static void Eigen::ei_assign_impl<Derived1, Derived2, 2, 0>::run(Derived1&, const Derived2&) [with Derived1 = Eigen::Matrix<double, 10000, 10000, 2, 6, 6>; Derived2 = Eigen::Product<const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, 0>]' My_ERGM line 397, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\Assign.h C/C++ Problem
required from 'static void Eigen::ei_compute_inverse<Derived, OtherDerived, Size>::run(const Derived&, OtherDerived*) [with Derived = Eigen::Matrix<double, 6, 6>; OtherDerived = Eigen::Matrix<double, 6, 6>; int Size = 6]' My_ERGM line 238, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\LU\Inverse.h C/C++ Problem
required from 'static void Eigen::ei_solve_triangular_selector<Lhs, Rhs, UpLo, 0>::run(const Lhs&, Rhs&) [with Lhs = Eigen::Flagged<Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>, 2304, 0>; Rhs = Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>; int UpLo = 2048]' My_ERGM line 189, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\SolveTriangular.h C/C++ Problem
required from 'void Eigen::LU<MatrixType>::computeInverse(ResultType*) const [with ResultType = Eigen::Matrix<double, 6, 6>; MatrixType = Eigen::Matrix<double, 6, 6>]' My_ERGM line 303, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\LU\LU.h C/C++ Problem
required from 'void Eigen::MatrixBase<Derived>::computeInverse(Eigen::MatrixBase<OtherDerived>*) const [with ResultType = Eigen::Matrix<double, 6, 6>; Derived = Eigen::Matrix<double, 6, 6>]' My_ERGM line 298, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\LU\Inverse.h C/C++ Problem
required from 'void Eigen::MatrixBase<Derived>::copyPacket(int, int, const Eigen::MatrixBase<OtherDerived>&) [with OtherDerived = Eigen::Product<const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, const Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>&, 0>; int StoreMode = 0; int LoadMode = 1; Derived = Eigen::Matrix<double, 10000, 10000, 2, 6, 6>]' My_ERGM line 362, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\Coeffs.h C/C++ Problem
required from 'void Eigen::MatrixBase<Derived>::solveTriangularInPlace(const Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived = Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>; Derived = Eigen::Flagged<Eigen::Block<Eigen::Matrix<double, 6, 6>, 10000, 10000, 1, 32>, 2304, 0>]' My_ERGM line 248, external location: C:\Program Files\Cpp_Libs\eigen2\Eigen\src\Core\SolveTriangular.h C/C++ Problem
required from here My_ERGM.cpp /My_ERGM/src line 99 C/C++ Problem


Too much errors and i cannot understand what is that! For Eigen 3, i will put it in an other issue.
hazemkrichene
Registered Member
Posts
7
Karma
0
I tried to execute my program by CMD command on windows and it runs perfectly. My command was
Code: Select all
g++ -I C:/Hazem/eigen2/ My_ERGM.cpp -o My_ERGM


Is it a problem of compiling from eclipse? On eclipse i included the path as follows: project -- properties -- settings -- GCC C++ complier -- Includes and i added the path: C:/Hazem/eigen2/

Is there anything else?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Yes this seems to be problem on your settings in eclipse. Look at the generated compilation command to see what could be wrong. And also, please move to Eigen 3.3.4!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
btw, your matrix is singular and not invertible.
hazemkrichene
Registered Member
Posts
7
Karma
0
Thank you for your advice. I moved to Eigen 3.4. I have eclipse Helios, and i'm not finding what i have to do. In the documentation they say as follows: http://eigen.tuxfamily.org/index.php?title=IDEs

However, i cannot find the path: Preferences > C/C++ > Coding Style > Organize Includes > Header Substitution.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]