Prev Next con_dyn_var.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}} }@)@ This is cppad-20221105 documentation. Here is a link to its current documentation .
AD Parameter and Variable Functions: Example and Test

# include <cppad/cppad.hpp>

bool con_dyn_var(void)
{   bool ok = true;

    using CppAD::AD;
    using CppAD::VecAD;
    using CppAD::Parameter;
    using CppAD::Variable;

    // No recording active
    CPPAD_TESTVECTOR(AD<double>) x(1), y(1), dynamic(1);
    x[0]        = 0.0;
    y[0]        = 1.0;
    dynamic[0]  = 2.0;
    //
    ok &= Constant(x[0]);
    ok &= Parameter(x[0]);
    ok &= ! Dynamic(x[0]);
    ok &= ! Variable(x[0]);
    //
    ok &= Constant(y[0]);
    ok &= Parameter(y[0]);
    ok &= ! Dynamic(y[0]);
    ok &= ! Variable(y[0]);
    //
    ok &= Constant(dynamic[0]);
    ok &= Parameter(dynamic[0]);
    ok &= ! Dynamic(dynamic[0]);
    ok &= ! Variable(dynamic[0]);

    // declare independent variables and start recording
    CppAD::Independent(x, dynamic);
    //
    ok &= Variable(x[0]);
    ok &= ! Constant(x[0]);
    ok &= ! Dynamic(x[0]);
    ok &= ! Parameter(x[0]);
    //
    ok &= Constant(y[0]);
    ok &= Parameter(y[0]);
    ok &= ! Dynamic(y[0]);
    ok &= ! Variable(y[0]);
    //
    ok &= Dynamic(dynamic[0]);
    ok &= Parameter(dynamic[0]);
    ok &= ! Constant(dynamic[0]);
    ok &= ! Variable(dynamic[0]);

    // a dependent variable
    y[0] = fabs(x[0]) * dynamic[0];
    ok  &= Variable(y[0]);
    ok  &= ! Constant(y[0]);
    ok  &= ! Dynamic(y[0]);
    ok  &= ! Parameter(y[0]);

    // create f: x -> y and stop tape recording
    CppAD::ADFun<double> f(x, y);
    //
    ok &= Constant(x[0]);
    ok &= Parameter(x[0]);
    ok &= ! Dynamic(x[0]);
    ok &= ! Variable(x[0]);
    //
    ok &= Constant(y[0]);
    ok &= Parameter(y[0]);
    ok &= ! Dynamic(y[0]);
    ok &= ! Variable(y[0]);
    //
    ok &= Constant(dynamic[0]);
    ok &= Parameter(dynamic[0]);
    ok &= ! Dynamic(dynamic[0]);
    ok &= ! Variable(dynamic[0]);

    return ok;
}

Input File: example/general/con_dyn_var.cpp