[ADMB Users] how to calculate the hessian matrix by autodif library

dave fournier davef at otter-rsch.com
Mon Oct 11 09:13:15 PDT 2010


I made a little example to compare the fmm Hessian with the finite 
difference Hessian.
Note that since the example is quadratic the finite difference hessian 
is exact.


#include <admodel.h>


dmatrix fmm::hessian(void)
{
   dmatrix tmp(1,n,1,n);
   for (int i=1;i<=n;i++)
     for (int j=1;j<=n;j++)
       tmp(i,j)=h(i,j);
   return tmp;
}

double func2(const dvar_vector & x)
{
   dvariable f;
   f=norm2(x-1.0);
   return value(f);
}

int main()
{
     int nvar=5;
     independent_variables x(1,nvar);
"h.cpp" 66L, 1341C                                            
1,1           Top




More information about the Users mailing list