Prev Next a_fun_optimize_xam.m Headings

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
Octave: Optimize an a_fun: Example and Test
function ok = a_fun_optimize_xam()
     %
     % load the Cppad Swig library
     m_cppad
     %
     % initialize return variable
     ok = true;
     % -----------------------------------------------------------------------
     n_ind = 1; % number of independent variables
     n_dep = 1; % number of dependent variables
     n_var = 1; % phantom variable at address 0
     n_op = 1;  % special operator at beginning
     %
     % dimension some vectors
     x = m_cppad.vec_double(n_ind);
     ay = m_cppad.vec_a_double(n_dep);
     %
     % independent variables
     x(0) = 1.0;
     ax = m_cppad.independent(x);
     n_var = n_var + n_ind; % one for each indpendent
     n_op = n_op + n_ind;
     %
     % accumulate summation
     ax0 = ax(0);
     csum = m_cppad.a_double(0.0);
     csum = ax0 + ax0 + ax0 + ax0;
     n_var = n_var + 3; % one per + operator
     n_op = n_op + 3;
     %
     % define f(x) = y_0 = csum
     ay(0) = csum;
     af = m_cppad.a_fun(ax, ay);
     n_op = n_op + 1; % speical operator at end
     %
     % check number of variables and operators
     ok = ok && af.size_var() == n_var;
     ok = ok && af.size_op() == n_op;
     %
     % optimize
     af.optimize();
     %
     % number of variables and operators has decreased by two
     ok = ok && af.size_var() == n_var-2;
     ok = ok && af.size_op() == n_op-2;
     %
     return;
end

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