|
Prev | Next | a_fun_hessian_xam.m | Headings |
function ok = a_fun_hessian_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);
%
% g(x) = w_0 * f_0 (x) = f(x)
w = m_cppad.vec_double(n_dep);
w(0) = 1.0;
%
% compute Hessian
fpp = af.hessian(x, w);
%
% [ 0.0 , x_2 , x_1 ]
% f''(x) = [ x_2 , 0.0 , x_0 ]
% [ x_1 , x_0 , 0.0 ]
ok = ok && fpp(0 * n_ind + 0) == 0.0 ;
ok = ok && fpp(0 * n_ind + 1) == x(2) ;
ok = ok && fpp(0 * n_ind + 2) == x(1) ;
%
ok = ok && fpp(1 * n_ind + 0) == x(2) ;
ok = ok && fpp(1 * n_ind + 1) == 0.0 ;
ok = ok && fpp(1 * n_ind + 2) == x(0) ;
%
ok = ok && fpp(2 * n_ind + 0) == x(1) ;
ok = ok && fpp(2 * n_ind + 1) == x(0) ;
ok = ok && fpp(2 * n_ind + 2) == 0.0 ;
%
return;
end