an_ode

View page source

An ODE Solution

ODE

\[\begin{split}\begin{array}{llll} y_i '(t) & = & x_0 & \mbox{for} \; i = 0 \\ y_i '(t) & = & \sum_{j=1}^i x_j y_{i-1} (t) & \mbox{for} \; i > 0 \\ \end{array}\end{split}\]

Parameter Vector

We refer to \(x\) as the parameter vector in the ode.

Initial Value

\[y_i (0) = 0 \; \mbox{for all} \; i\]

Solution

This initial value problem has the following analytic solution (which can be used to check function values and derivatives):

\[\begin{split}\begin{array}{llll} y_0 (t) & = & x_0 t \\ y_1 (t) & = & x_0 x_1 t^2 / 2 ! \\ y_2 (t) & = & x_0 x_1 x_2 t^3 / 3 ! \end{array}\end{split}\]
\[y_i (t) = \frac{t^{i+1}}{(i+1)!} \prod_{j=0}^i x_j \; \; \mbox{for all} \; i\]

Algorithm

The rk4_step method is used to approximate the solution for \(y(t)\) at \(t = 2\) . Note that this approximation has no truncation error for \(i < 4\) .

option

This algorithm uses the n_arg and n_other options; see below:

n_arg

This is the size of the vectors x and y above . There is an assert checking that n_arg > 0.

n_other

This is the number of Runge-Kutta steps used to approximate the solution of the ODE \(y(t)\) . There is an assert checking that n_other > 0.

Implementation

rk4_step , cpp_an_ode , py_an_ode .

Derivative

The partial of \(y_i (t)\) with respect to \(x_j\) is

\[\begin{split}\frac{ \partial y_i (t) }{ \partial x_j } = \begin{cases} y_i (t) / x_j & \text{if} \; j \leq i \\ 0 & \text{otherwise} \end{cases}\end{split}\]