[CppAD] RevTwo problem
Kasper Kristensen
kkr at dfu.min.dk
Mon Feb 20 14:43:32 EST 2006
Dear list,
I have been trying to compute specific rows in the hessian of a simple
function F:R^2->R using the "RevTwo" method of an ADFun object. Running
the attached code with the latest version of the library I get the
following output:
Hessian: { 8.2999, 2.93431, 2.93431, 6.28781 }
First row: { 8.2999, 2.93431 }
Second row: { 5.30565e-312, 5.19526e-270 }
Could someone please tell me why this goes wrong?
Best regards
Kasper Kristensen
CODE SAMPLE:
#include <CppAD/CppAD.h>
using namespace CppAD;
int main()
{
vector<AD<double> > x(2);
vector<AD<double> > y(1);
Independent(x);
y[0]=exp(x[0]*x[0]+x[1]*x[1]);
ADFun<double> F(x,y);
vector<double> x0(2);
x0[0]=0.7; x0[1]=0.5;
std::cout << "Hessian: " << F.Hessian(x0,0) << "\n";
vector<size_t> I(1);
vector<size_t> J(1);
I[0]=0;
J[0]=0;
std::cout << "First row: " << F.RevTwo(x0,I,J) << "\n";
J[0]=1;
std::cout << "Second row: " << F.RevTwo(x0,I,J) << "\n";
}
More information about the CppAD
mailing list