Prev Next a_fun_jacobian_xam.m Headings

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
Octave: Dense Jacobian Using AD: Example and Test
function ok = a_fun_jacobian_xam()
     %
     % load the Cppad Swig library
     m_cppad
     %
     % initialize return variable
     ok = true;
     % -----------------------------------------------------------------------
     % number of dependent and independent variables
     n_dep = 1;
     n_ind = 3;
     %
     % create the independent variables ax
     x = m_cppad.vec_double(n_ind);
     for i = [ 0 :(n_ind -1) ]
          x(i) = i + 2.0;
     end
     ax = m_cppad.independent(x);
     %
     % create dependent variables ay with ay0 = ax_0 * ax_1 * ax_2
     ax_0 = ax(0);
     ax_1 = ax(1);
     ax_2 = ax(2);
     ay = m_cppad.vec_a_double(n_dep);
     ay(0) = ax_0 * ax_1 * ax_2;
     %
     % define af corresponding to f(x) = x_0 * x_1 * x_2
     af = m_cppad.a_fun(ax, ay);
     %
     % compute the Jacobian f'(x) = ( x_1*x_2, x_0*x_2, x_0*x_1 )
     fp = af.jacobian(x);
     %
     % check Jacobian
     x_0 = x(0);
     x_1 = x(1);
     x_2 = x(2);
     ok = ok && fp(0 * n_ind + 0) == x_1 * x_2 ;
     ok = ok && fp(0 * n_ind + 1) == x_0 * x_2 ;
     ok = ok && fp(0 * n_ind + 2) == x_0 * x_1 ;
     %
     return;
end

Input File: build/lib/example/octave/a_fun_jacobian_xam.m