The typedouble function is imsl_d_ode_adams_krogh.
Required Arguments
intneq (Input) Number of differential equations in the system of equations to solve.
float*t (Input/Output) On input, t contains the initial independent variable value. On output, t is replaced by tend unless error conditions arise. See ido for details.
floattend (Input) Value of t= tend where the solution is required.
int*ido (Input/Output) Flag indicating the state of the computation.
ido
State
1
Initial entry input value.
2
Normal re-entry input value. On output, if ido = 2 then the integration is finished. If the integrator is called with a new value for tend, the integration continues. If the integrator is called with tend unchanged, an error message is issued.
3
Input value to use on final call to release workspace.
>3
Output value that indicates that a fatal error has occurred.
The initial call is made with ido = 1. The function then sets ido = 2, and this value is used for all but the last call that is made with ido = 3. This final call is only used to release workspace which was automatically allocated by the initial call with ido = 1.
floaty[] (Input/Output) An array of length k containing the dependent variables, y(t), and first derivatives, if any. k will be the sum of the orders of the equations in the system of equations to solve, that is, the sum of the elements of korder. On input, y contains the initial values, y(t0) and y’(t0) (if needed). On output, y contains the approximate solution, y(t). For example, for a system of first order equations, y[i‑1] is the i‑th dependent variable. For a system of second order equations, y[2i‑2] is thei‑th dependent variable and y[2i‑1] is the derivative of the i‑th dependent variable. For systems of equations in which one or more equations is of order 2, optional argument IMSL_EQ_ORDER must be used to denote the order of each equation so that the derivatives in y can be identified. By default it is assumed that all equations are of order 1 and y contains only dependent variables.
floathidrvs[] (Output) An array of length neq containing the highest order derivatives at the point y.
voidfcn (intneq, intido, floatt, floaty[], floathidrvs) (Input) User-supplied function to evaluate derivatives.
Arguments
intneq (Input) Number of differential equations in the system of equations to solve.
intido (Input) Flag indicating the state of the computation. This flag corresponds to the ido argument described above. If fcn has complicated subexpressions, which depend only weakly or not at all on y then these subexpressions need only be computed when ido = 1 and their values then reused when ido= 2.
floatt (Input) Independent variable, t.
floaty[] (Input) An array of length k containing the dependent variable values, y,and first derivatives, if any. k will be the sum of the orders of the equations in the system of equations to solve.
floathidrvs[] (Output) An array of length neq containing the values of the highest order derivatives evaluated at (t, y).
IMSL_EQ_ORDER, intkorder[] (Input) An array of length neq specifying the orders of the equations in the system of equations to solve. The elements of korder can be 1 or 2. korder must be used with argument y to define systems of mixed or higher order. Default: korder = [1,1,1,…,1].
IMSL_EQ_ERR, floateqnerr[] (Input) An array of length neq specifying the error tolerance for each equation. Let e(i) be the error tolerance for equation i for i = 0,…, neq‑1. Then
Value
Explanation
e(i) >0
Implies an absolute error tolerance of e(i) is to be used for equationi.
e(i) =0
Implies no error checking is to be performed for equation i.
e(i) <0
Implies a relative error test is to be performed for equation i. In this case, the base error tolerance used will be |e(i)| and the relative error factor used will be (15/16 * |e(i)|). Thus the actual absolute error tolerance used will be |e(i)|×(15/16×|e(i)|).
Default: An absolute error tolerance of 1.e‑5 is used for single precision and 1.e‑10 for double precision for all equations.
IMSL_STEPSIZE_INC, floathinc (Input) Factor used for increasing the stepsize. One should set hinc such that 9/8 <= hinc <= 4. Default: hinc = 2.0.
IMSL_STEPSIZE_DEC, floathdec (Input) Factor used for decreasing the stepsize. One should set hdec such that 1/4 <= hdec <= 7/8. Default: hdec = 0.5.
IMSL_MIN_STEPSIZE, float hmin (Input) Absolute value of the minimum stepsize permitted. Default: hmin = 10.0/imsl_f_machine(2).
IMSL_MAX_STEPSIZE, floathmax (Input) Absolute value of the maximum stepsize permitted. Default: hmax = imsl_f_machine(2).
IMSL_FCN_W_DATA, void fcn(intneq, intido, floatt, floaty[], floathidrvs[], void*data), void*data (Input) User-supplied function to evaluate functions, which also accepts a pointer to data that is supplied by the user. data is a pointer to the data to be passed to the user-supplied function. Please refer to the fcn argument in the Required Arguments section for more information. See Passing Data to User-Supplied Functions in the introduction to this manual for more details.
Description
imsl_f_ode_adams_krogh is based on the JPL Library routine SIVA. imsl_f_ode_adams_krogh uses a variable order Adams method to solve the initial value problem
or more generally
where y is the vector
is the kth derivative of zi with respect to t, di is the order of the ith differential equation, and η is a vector with the same dimension as y.
Note that the systems of equations solved by imsl_f_ode_adams_krogh can be of order one, order two, or mixed order one and two.
See "Changing Stepsize in the Integration of Differential Equations Using Modified Divided Differences,” Krogh (1974).
Examples
Example 1
In this example a system of two equations of order two is solved.
The initial conditions are
Since the system is of order two, optional argument imsl_eq_order must be used to specify the orders of the equations. Also, because the system is of order two, y[0] contains the first dependent variable, y[1] contains the derivative of the first dependent variable, y[2] contains the second dependent variable, and y[3] contains the derivative of the second dependent variable.
This contrived example illustrates how to use imsl_f_ode_adams_krogh to solve a system of equations of mixed order.
The height, y(t), of an object of mass m above the surface of the Earth can be modeled using Newton's second law as:
or
where ‑mg is the downward force of gravity and ‑ky' is the force due to air resistance, in a direction opposing the velocity. If the object is a meteor, the mass, m, and air resistance, k, will decrease as the meteor burns up in the atmosphere. The mass is proportional to r3 (r = radius) and the air resistance, presumably dependent on the surface area, may be assumed to be proportional to r2, so that k/m = k0/r. The rate at which the meteor’s radius decreases as it burns up may depend on r, on the velocity y', and, since the density of the atmosphere depends on y, on y itself. However, we will construct a very simple model where the rate is just proportional to the square of the velocity,
We solve (1) and (2), with k0 = 0.005, c0 = 10-8, g = 9.8 and initial conditions y(0) = 100,000 meters, y'(0) = ‑1000 meters/second, r(0) = 1 meter.
The requested error tolerance, # is too small. Using # instead.
IMSL_RESTART
The stepsize has been reduced too rapidly The integrator is going to do a restart.
Fatal Errors
IMSL_ADJUST_STEPSIZE1
The current step length = #, is less than the minimum steplength, “hmin” = #, at the conclusion of the starting phase of the integration. Decreasing “hmin” to a value less than or equal to # may help.
IMSL_ADJUST_STEPSIZE2
The integrator needs to take a step smaller than # in order to maintain the requested local error. Decreasing “hmin” to a value less than or equal to # may help.
IMSL_INCORRECT_TEND
Either the new output point precedes the last one or it has the same value. “tend” = #.
IMSL_ADJUST_ERROR_TOLERANCE
The step length, H = #, is so small that when Tn + H is formed, the result will be the same as Tn, where Tn is the base value of the independent variable. If this problem is not due to a nonintegrable singularity, it can probably be corrected by translating “t” so that it is closer to 0. Reducing the error tolerance for the equations through argument “eqnerr” may also help with this problem.
IMSL_ERROR_TOLERANCE
A local error tolerance of zero has been requested.
IMSL_ERROR_PREVIOUS
A fatal error has occurred because of the error reported in the previous error message.
IMSL_STOP_USER_FCN
Request from user supplied function to stop algorithm. User flag = "#".