Prev Next Index-> contents reference index search external Up-> CppAD Introduction exp_2 exp_2_for2 exp_2_for2.cpp Introduction-> exp_2 exp_eps exp_apx.cpp exp_2-> exp_2.hpp exp_2.cpp exp_2_for0 exp_2_for1 exp_2_rev1 exp_2_for2 exp_2_rev2 exp_2_cppad exp_2_for2-> exp_2_for2.cpp exp_2_for2.cpp Headings

$\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }$
exp_2: Verify Second Order Forward Sweep
# include <cmath>                   // prototype for fabs
extern bool exp_2_for0(double *v0); // computes zero order forward sweep
extern bool exp_2_for1(double *v1); // computes first order forward sweep
bool exp_2_for2(void)
{     bool ok = true;
double v0[6], v1[6], v2[6];

// set the value of v0[j], v1[j], for j = 1 , ... , 5
ok &= exp_2_for0(v0);
ok &= exp_2_for1(v1);

v2[1] = 0.;                                     // v1 = x
ok    &= std::fabs( v2[1] - 0. ) <= 1e-10;

v2[2] = v2[1];                                  // v2 = 1 + v1
ok    &= std::fabs( v2[2] - 0. ) <= 1e-10;

v2[3] = 2.*(v0[1]*v2[1] + v1[1]*v1[1]);         // v3 = v1 * v1
ok    &= std::fabs( v2[3] - 2. ) <= 1e-10;

v2[4] = v2[3] / 2.;                             // v4 = v3 / 2
ok    &= std::fabs( v2[4] - 1. ) <= 1e-10;

v2[5] = v2[2] + v2[4];                          // v5 = v2 + v4
ok    &= std::fabs( v2[5] - 1. ) <= 1e-10;

return ok;
}

Input File: introduction/exp_2_for2.cpp