![]() |
Prev | Next |
# include <cppad/ode_gear_control.hpp>
xf = OdeGearControl(
F,
M,
ti,
tf,
xi,
smin,
smax,
sini,
eabs,
erel,
ef ,
maxabs,
nstep )
\R
denote the real numbers
and let
f : \R \times \R^n \rightarrow \R^n
be a smooth function.
We define
X : [ti , tf] \rightarrow \R^n
by
the following initial value problem:
\[
\begin{array}{rcl}
X(ti) & = & xi \\
X'(t) & = & f[t , X(t)]
\end{array}
\]
The routine OdeGear
is a stiff multi-step method that
can be used to approximate the solution to this equation.
The routine OdeGearControl
sets up this multi-step method
and controls the error during such an approximation.
cppad/ode_gear_control.hpp
is included by cppad/cppad.hpp
but it can also be included separately with out the rest of
the CppAD
routines.
Vector
xf
and the size of xf is equal to n
(see description of Vector
below).
It is the approximation for
X(tf)
.
Fun &
F
This must support the following set of calls
F.Ode(
t,
x,
f)
F.Ode_dep(
t,
x,
f_x)
const
Scalar &
t
(see description of Scalar
below).
const
Vector &
x
and has size N
(see description of Vector
below).
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
).
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] = \partial_{x(j)} f_i ( t , x )
\]
&
in the prototype for
f and f_x.
size_t
M
It specifies the order of the multi-step method; i.e.,
the order of the approximating polynomial
(after the initialization process).
The argument M must greater than or equal one.
const
Scalar &
ti
It specifies the initial time for the integration of
the differential equation.
const
Scalar &
tf
It specifies the final time for the integration of
the differential equation.
const
Vector &
xi
and size n.
It specifies value of
X(ti)
.
const
Scalar &
smin
The minimum value of
T[M] - T[M-1]
in a call to OdeGear
will be
smin
except for the last two calls where it may be
as small as
smin / 2
.
The value of smin must be less than or equal smax.
const
Scalar &
smax
It specifies the maximum step size to use during the integration;
i.e., the maximum value for
T[M] - T[M-1]
in a call to OdeGear
.
Scalar &
sini
The value of sini is the minimum
step size to use during initialization of the multi-step method; i.e.,
for calls to OdeGear
where
m < M
.
The value of sini must be less than or equal smax
(and can also be less than smin).
const
Vector &
eabs
and size n.
Each of the elements of eabs must be
greater than or equal zero.
It specifies a bound for the absolute
error in the return value xf as an approximation for
X(tf)
.
(see the
error criteria discussion
below).
const
Scalar &
erel
and is greater than or equal zero.
It specifies a bound for the relative
error in the return value xf as an approximation for
X(tf)
(see the
error criteria discussion
below).
Vector &
ef
and size n.
The input value of its elements does not matter.
On output,
it contains an estimated bound for the
absolute error in the approximation xf; i.e.,
\[
ef_i > | X( tf )_i - xf_i |
\]
OdeGearControl
.
If it is present, it has the prototype
Vector &
maxabs
and size n.
The input value of its elements does not matter.
On output,
it contains an estimate for the
maximum absolute value of
X(t)
; i.e.,
\[
maxabs[i] \approx \max \left\{
| X( t )_i | \; : \; t \in [ti, tf]
\right\}
\]
size_t &
nstep
Its input value does not matter and its output value
is the number of calls to OdeGear
used by OdeGearControl
.
\tilde{X} (t)
is the approximate solution
at time
t
,
ta is the initial step time,
and tb is the final step time,
\[
\left| \tilde{X} (tb)_j - X (tb)_j \right|
\leq
\frac{tf - ti}{tb - ta}
\left[ eabs[j] + erel \; | \tilde{X} (tb)_j | \right]
\]
If
X(tb)_j
is near zero for some
tb \in [ti , tf]
,
and one uses an absolute error criteria
eabs[j]
of zero,
the error criteria above will force OdeGearControl
to use step sizes equal to
smin
for steps ending near
tb
.
In this case, the error relative to maxabs can be judged after
OdeGearControl
returns.
If ef is to large relative to maxabs,
OdeGearControl
can be called again
with a smaller value of smin.
Operation | Description |
a <= b | returns true (false) if a is less than or equal (greater than) b. |
a == b | returns true (false) if a is equal to b. |
log( a) | returns a Scalar equal to the logarithm of a |
exp( a) | returns a Scalar equal to the exponential of a |
e(s)
be the error as a function of the
step size
s
and suppose that there is a constant
K
such that
e(s) = K s^m
.
Let
a
be our error bound.
Given the value of
e(s)
, a step of size
\lambda s
would be ok provided that
\[
\begin{array}{rcl}
a & \geq & e( \lambda s ) (tf - ti) / ( \lambda s ) \\
a & \geq & K \lambda^m s^m (tf - ti) / ( \lambda s ) \\
a & \geq & \lambda^{m-1} s^{m-1} (tf - ti) e(s) / s^m \\
a & \geq & \lambda^{m-1} (tf - ti) e(s) / s \\
\lambda^{m-1} & \leq & \frac{a}{e(s)} \frac{s}{tf - ti}
\end{array}
\]
Thus if the right hand side of the last inequality is greater
than or equal to one, the step of size
s
is ok.
cppad/ode_gear_control.hpp
.