Prev Next poly.hpp 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 .
Source: Poly
# ifndef CPPAD_POLY_HPP
# define CPPAD_POLY_HPP
# include <cstddef>  // used to defined size_t
# include <cppad/utility/check_simple_vector.hpp>

namespace CppAD {    // BEGIN CppAD namespace

template <class Type, class Vector>
Type Poly(size_t k, const Vector &a, const Type &z)
{   size_t i;
    size_t d = a.size() - 1;

    Type tmp;

    // check Vector is Simple Vector class with Type elements
    CheckSimpleVector<Type, Vector>();

    // case where derivative order greater than degree of polynomial
    if( k > d )
    {   tmp = 0;
        return tmp;
    }
    // case where we are evaluating a derivative
    if( k > 0 )
    {   // initialize factor as (k-1) !
        size_t factor = 1;
        for(i = 2; i < k; i++)
            factor *= i;

        // set b to coefficient vector corresponding to derivative
        Vector b(d - k + 1);
        for(i = k; i <= d; i++)
        {   factor   *= i;
            tmp       = double( factor );
            b[i - k]  = a[i] * tmp;
            factor   /= (i - k + 1);
        }
        // value of derivative polynomial
        return Poly(0, b, z);
    }
    // case where we are evaluating the original polynomial
    Type sum = a[d];
    i        = d;
    while(i > 0)
    {   sum *= z;
        sum += a[--i];
    }
    return sum;
}
} // END CppAD namespace
# endif

Input File: omh/poly_hpp.omh