An Arbitrary Order Gear Method
Keywords: arbitrary order gear method Odegear Ode stiff differential equation syntax purpose include fun t x f f_x warning m n e scalar vector example source code theory gear's

| Prev | Next |  |  |  |  |  |

An Arbitrary Order Gear Method
Syntax
`# include <cppad/utility/ode_gear.hpp>
` `OdeGear(F, m, n, T, X, e)`
Purpose
This routine applies Gear's Method to solve an explicit set of ordinary differential equations. We are given f : R × R n → R n be a smooth function. This routine solves the following initial value problem x ( t m -1 ) = x 0 x ′ ( t ) = f [ t , x ( t ) ] for the value of x ( t m ) . If your set of ordinary differential equations are not stiff an explicit method may be better (perhaps Runge45 .)
Include
The file `cppad/ode_gear.hpp` is included by `cppad/cppad.hpp` but it can also be included separately with out the rest of the `CppAD` routines.
Fun
The class `Fun` and the object `F` satisfy the prototype `
Fun &F
` This must support the following set of calls `
F.Ode(t, x, f)
F.Ode_dep(t, x, f_x)
`
t
The argument `t` has prototype `
const Scalar &t
` (see description of Scalar below).
x
The argument `x` has prototype `
const Vector &x
` and has size `n` (see description of Vector below).
f
The argument `f` to `F.Ode` has prototype `
Vector &f
` On input and output, `f` is a vector of size `n` and the input values of the elements of `f` do not matter. On output, `f` is set equal to f ( t , x ) (see `f(t, x)` in Purpose ).
f_x
The argument `f_x` has prototype `
Vector &f_x
` On input and output, `f_x` is a vector of size n * n and the input values of the elements of `f_x` do not matter. On output, f _ x [ i * n + j ] = ∂ x ( j ) f i ( t , x )
Warning
The arguments `f` , and `f_x` must have a call by reference in their prototypes; i.e., do not forget the `&` in the prototype for `f` and `f_x` .
m
The argument `m` has prototype `
size_t m
` It specifies the order (highest power of t ) used to represent the function x ( t ) in the multi-step method. Upon return from `OdeGear`, the `i`-th component of the polynomial is defined by p i ( t j ) = X [ j * n + i ] for j = 0 , … , m (where 0 ≤ i < n ). The value of m must be greater than or equal one.
n
The argument `n` has prototype `
size_t n
` It specifies the range space dimension of the vector valued function x ( t ) .
T
The argument `T` has prototype `
const Vector &T
` and size greater than or equal to m + 1 . For j = 0 , … m , T [ j ] is the time corresponding to time corresponding to a previous point in the multi-step method. The value T [ m ] is the time of the next point in the multi-step method. The array T must be monotone increasing; i.e., T [ j ] < T [ j + 1 ] . Above and below we often use the shorthand t j for T [ j ] .
X
The argument `X` has the prototype `
Vector &X
` and size greater than or equal to ( m + 1 ) * n . On input to `OdeGear`, for j = 0 , … , m -1 , and i = 0 , … , n -1 X [ j * n + i ] = x i ( t j ) Upon return from `OdeGear`, for i = 0 , … , n -1 X [ m * n + i ] ≈ x i ( t m )
e
The vector `e` is an approximate error bound for the result; i.e., e [ i ] ≥ | X [ m * n + i ] - x i ( t m ) | The order of this approximation is one less than the order of the solution; i.e., e = O ( h m ) where h is the maximum of t j + 1 - t j .
Scalar
The type `Scalar` must satisfy the conditions for a NumericType type. The routine CheckNumericType will generate an error message if this is not the case. In addition, the following operations must be defined for `Scalar` objects `a` and `b` :

Operation | Description
`a < b` | less than operator (returns a `bool` object)

Vector
The type `Vector` must be a SimpleVector class with elements of type Scalar . The routine CheckSimpleVector will generate an error message if this is not the case.
Example
The file ode_gear.cpp contains an example and test a test of using this routine. It returns true if it succeeds and false otherwise.
Source Code
The source code for this routine is in the file `cppad/ode_gear.hpp`.
Theory
For this discussion we use the shorthand x j for the value x ( t j ) ∈ R n which is not to be confused with x i ( t ) ∈ R in the notation above. The interpolating polynomial p ( t ) is given by p ( t ) = ∑ j = 0 m x j ∏ i ≠ j ( t - t i ) ∏ i ≠ j ( t j - t i ) The derivative p ′ ( t ) is given by p ′ ( t ) = ∑ j = 0 m x j ∑ i ≠ j ∏ k ≠ i , j ( t - t k ) ∏ k ≠ j ( t j - t k ) Evaluating the derivative at the point t ℓ we have p ′ ( t ℓ ) = x ℓ ∑ i ≠ ℓ ∏ k ≠ i , ℓ ( t ℓ - t k ) ∏ k ≠ ℓ ( t ℓ - t k ) + ∑ j ≠ ℓ x j ∑ i ≠ j ∏ k ≠ i , j ( t ℓ - t k ) ∏ k ≠ j ( t j - t k ) = x ℓ ∑ i ≠ ℓ 1 t ℓ - t i + ∑ j ≠ ℓ x j ∏ k ≠ ℓ , j ( t ℓ - t k ) ∏ k ≠ j ( t j - t k ) = x ℓ ∑ k ≠ ℓ ( t ℓ - t k ) -1 + ∑ j ≠ ℓ x j ( t j - t ℓ ) -1 ∏ k ≠ ℓ , j ( t ℓ - t k ) / ( t j - t k ) We define the vector α ∈ R m + 1 by α j = { ∑ k ≠ m ( t m - t k ) -1 if j = m ( t j - t m ) -1 ∏ k ≠ m , j ( t m - t k ) / ( t j - t k ) otherwise It follows that p ′ ( t m ) = α 0 x 0 + ⋯ + α m x m Gear's method determines x m by solving the following nonlinear equation f ( t m , x m ) = α 0 x 0 + ⋯ + α m x m Newton's method for solving this equation determines iterates, which we denote by x m k , by solving the following affine approximation of the equation above f ( t m , x m k -1 ) + ∂ x f ( t m , x m k -1 ) ( x m k - x m k -1 ) = α 0 x 0 k + α 1 x 1 + ⋯ + α m x m [α m I - ∂ x f ( t m , x m k -1 ) ] x m = [f ( t m , x m k -1 ) - ∂ x f ( t m , x m k -1 ) x m k -1 - α 0 x 0 - ⋯ - α m -1 x m -1 ] In order to initialize Newton's method; i.e. choose x m 0 we define the vector β ∈ R m + 1 by β j = { ∑ k ≠ m -1 ( t m -1 - t k ) -1 if j = m -1 ( t j - t m -1 ) -1 ∏ k ≠ m -1 , j ( t m -1 - t k ) / ( t j - t k ) otherwise It follows that p ′ ( t m -1 ) = β 0 x 0 + ⋯ + β m x m We solve the following approximation of the equation above to determine x m 0 : f ( t m -1 , x m -1 ) = β 0 x 0 + ⋯ + β m -1 x m -1 + β m x m 0
Gear's Method
C. W. Gear, ``Simultaneous Numerical Solution of Differential-Algebraic Equations,'' IEEE Transactions on Circuit Theory, vol. 18, no. 1, pp. 89-95, Jan. 1971.

Input File: cppad/utility/ode_gear.hpp