[CppAD] Using eigenvalues from Eigen in CppAD with Ipopt

Jyotiranjan Beuria jyotiranjan.beuria at gmail.com
Sun May 21 13:20:53 EDT 2017


I figured out the following. I hope it is internally consistent and would
not spoil for more complicated situations.

typedef Matrix<CppAD::AD<double>, Dynamic, Dynamic> MatrixXdAD;
namespace {
using CppAD::AD;

class FG_eval {
public:
typedef CPPAD_TESTVECTOR( AD<double> ) ADvector;
void operator()(ADvector& fg, const ADvector& x)
{
  AD<double> x1 = x[0];
  MatrixXdAD m(2,2);
  m(0,0)=x1*x1;
  m(0,1)= x1;
  m(1,0)= 1.0;
  m(1,1)= x1+x1*x1-1.0;
          EigenSolver<MatrixXdAD> es(m);
          AD<double> y1=es.eigenvalues().real()[0];
          AD<double> y2=es.eigenvalues().real()[1];
  // f(x)
  fg[0] = y1+y2;
   //
  return;
}
};
}

Regards,
Jyotiranjan

On Sun, May 21, 2017 at 6:10 PM, Jyotiranjan Beuria <
jyotiranjan.beuria at gmail.com> wrote:

> Dear All,
>
> I am trying to use CppAD along with Ipopt. However, my function
> depends on eigenvalues and for that I am trying to use Eigen.
>
> A snippet of the code for a simple case is as follows:
>
>
>
>
>
>
>
>
>
>
> *          AD<double> x1 = x[0];            MatrixXd m(2,2);
> m(0,0)=x1*x1;          m(0,1)= x1;          m(1,0)= 1.0;          m(1,1)=
> x1+x1*x1-1.0;          EigenSolver<MatrixXd> es(m);          AD<double>
> y=es.eigenvalues();          // f(x)          fg[0] = y[0]+y[1];  *
>
> I get following error.
>
> *error: cannot convert ‘CppAD::AD<double>’ to
> ‘Eigen::DenseCoeffsBase<Eigen:*
>
>
>
>
>
>
>
>
> *:Matrix<double, -1, -1>, 1>::Scalar {aka double}’ in
> assignmentmyTest.cpp:31:36: error: conversion from ‘const EigenvalueType
> {aka const Eigen::Matrix<std::complex<double>, -1, 1>}’ to non-scalar type
> ‘CppAD::AD<double>’ requested       AD<double>
> y=es.eigenvalues();                                    ^myTest.cpp:33:15:
> error: no match for call to ‘(CppAD::AD<double>) (int)’    fg[0] =
> y(0)+y(1);*
> Can anyone help?
>
> Regards,
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cppad/attachments/20170521/eec01daa/attachment.html>


More information about the CppAD mailing list