lines 7-99 of file: example/general/base2ad.cpp

{xrst_begin base2ad.cpp}
{xrst_spell
   cccc
}

Taylor's Ode Solver: base2ad Example and Test
#############################################

See Also
********
:ref:`taylor_ode.cpp-name` , :ref:`mul_level_ode.cpp-name`

Purpose
*******
This is a realistic example using :ref:`base2ad-name` to create
an ``AD`` < *Base* > function from an *Base* function.
The function represents an ordinary differential equation.
It is differentiated with respect to
its :ref:`variables<glossary@Variable>` .
These derivatives are used by the :ref:`taylor_ode-name` method.
This solution is then differentiated with respect to
the functions :ref:`dynamic parameters<glossary@Parameter@Dynamic>` .

ODE
***
For this example the function
:math:`y : \B{R} \times \B{R}^n \rightarrow \B{R}^n` is defined by
:math:`y(0, x) = 0` and
:math:`\partial_t y(t, x) = g(y, x)` where
:math:`g : \B{R}^n \times \B{R}^n \rightarrow \B{R}^n` is defined by

.. math::

   g(y, x) =
   \left( \begin{array}{c}
         x_0     \\
         x_1 y_0 \\
         \vdots  \\
         x_{n-1} y_{n-2}
   \end{array} \right)

ODE Solution
************
The solution for this example can be calculated by
starting with the first row and then using the solution
for the first row to solve the second and so on.
Doing this we obtain

.. math::

   y(t, x ) =
   \left( \begin{array}{c}
      x_0 t                  \\
      x_1 x_0 t^2 / 2        \\
      \vdots                 \\
      x_{n-1} x_{n-2} \ldots x_0 t^n / n !
   \end{array} \right)

Derivative of ODE Solution
**************************
Differentiating the solution above,
with respect to the parameter vector :math:`x`,
we notice that

.. math::

   \partial_x y(t, x ) =
   \left( \begin{array}{cccc}
   y_0 (t,x) / x_0      & 0                   & \cdots & 0      \\
   y_1 (t,x) / x_0      & y_1 (t,x) / x_1     & 0      & \vdots \\
   \vdots               & \vdots              & \ddots & 0      \\
   y_{n-1} (t,x) / x_0  & y_{n-1} (t,x) / x_1 & \cdots & y_{n-1} (t,x) / x_{n-1}
   \end{array} \right)

Taylor's Method Using AD
************************
We define the function :math:`z(t, x)` by the equation

.. math::

   z ( t , x ) = g[ y ( t , x ), x ]

see :ref:`taylor_ode-name` for the method used to compute the
Taylor coefficients w.r.t :math:`t` of :math:`y(t, x)`.

Source
******
{xrst_literal
   // BEGIN C++
   // END C++
}

{xrst_end base2ad.cpp}
