Prev Next ode_evaluate.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 .
ode_evaluate: Example and test
# include <cppad/speed/ode_evaluate.hpp>
# include <cppad/speed/uniform_01.hpp>
# include <cppad/cppad.hpp>

bool ode_evaluate(void)
{   using CppAD::NearEqual;
    using CppAD::AD;

    bool ok = true;

    size_t n = 3;
    CppAD::vector<double>       x(n);
    CppAD::vector<double>       ym(n * n);
    CppAD::vector< AD<double> > X(n);
    CppAD::vector< AD<double> > Ym(n);

    // choose x
    size_t j;
    for(j = 0; j < n; j++)
    {   x[j] = double(j + 1);
        X[j] = x[j];
    }

    // declare independent variables
    Independent(X);

    // evaluate function
    size_t m = 0;
    CppAD::ode_evaluate(X, m, Ym);

    // evaluate derivative
    m = 1;
    CppAD::ode_evaluate(x, m, ym);

    // use AD to evaluate derivative
    CppAD::ADFun<double>   F(X, Ym);
    CppAD::vector<double>  dy(n * n);
    dy = F.Jacobian(x);

    size_t k;
    for(k = 0; k < n * n; k++)
        ok &= NearEqual(ym[k], dy[k] , 1e-7, 1e-7);

    return ok;
}

Input File: speed/example/ode_evaluate.cpp