|
Prev | Next | a_fun_forward_xam.m | Headings |
function ok = a_fun_forward_xam()
%
% load the Cppad Swig library
m_cppad
%
% initialize return variable
ok = true;
% -----------------------------------------------------------------------
% number of dependent and independent variables
n_dep = 1;
n_ind = 2;
%
% create the independent variables ax
xp = m_cppad.vec_double(n_ind);
for i = [ 0 :(n_ind -1) ]
xp(i) = i + 1.0;
end
ax = m_cppad.independent(xp);
%
% create dependent varialbes ay with ay0 = ax0 * ax1
ax0 = ax(0);
ax1 = ax(1);
ay = m_cppad.vec_a_double(n_dep);
ay(0) = ax0 * ax1;
%
% define af corresponding to f(x) = x0 * x1
af = m_cppad.a_fun(ax, ay);
%
% define X(t) = (3 + t, 2 + t)
% it follows that Y(t) = f(X(t)) = (3 + t) * (2 + t)
%
% Y(0) = 6 and p ! = 1
p = 0;
xp(0) = 3.0;
xp(1) = 2.0;
yp = af.forward(p, xp);
ok = ok && yp(0) == 6.0;
%
% first order Taylor coefficients for X(t)
p = 1;
xp(0) = 1.0;
xp(1) = 1.0;
%
% first order Taylor coefficient for Y(t)
% Y'(0) = 3 + 2 = 5 and p ! = 1
yp = af.forward(p, xp);
ok = ok && yp(0) == 5.0;
%
% second order Taylor coefficients for X(t)
p = 2;
xp(0) = 0.0;
xp(1) = 0.0;
%
% second order Taylor coefficient for Y(t)
% Y''(0) = 2.0 and p ! = 2
yp = af.forward(p, xp);
ok = ok && yp(0) == 1.0;
%
return;
end