## LSODE

The LSODE function uses adaptive numerical methods to advance a solution to a system of ordinary differential equations one time-step H, given values for the variables Y and X .

### Calling Sequence

Result = LSODE( Y, X, H, Derivs[, Status] )

### Arguments

#### Y

A vector of values for Y at X

#### X

A scalar value for the initial condition.

#### H

A scalar value giving interval length or step size.

#### Derivs

A scalar string specifying the name of a user-supplied IDL function that calculates the values of the derivatives Dydx at X. This function must accept two arguments: A scalar floating value X , and one n-element vector Y . It must return an n -element vector result.

• Suppose the values of the derivatives are defined by the following relations:

dy 0 / dx = -0.5 y 0,         dy 1 / dx = 4.0 - 0.3 y 1 - 0.1 y 0

We can write a function called differential to express these relationships in the IDL language:

FUNCTION differential, X, Y

RETURN, [-0.5 * Y[0], 4.0 - 0.3 * Y[1] - 0.1 * Y[0]]

END

#### Status

An index used for input and output to specify the state of the calculation. This argument contains a positive value if the function was successfully completed. Negative values indicate different errors.

• Input Values for Status

Input Value

Description

1

This is the first call for the problem; initializations will occur. This is the default value.

2

This is not the first call. The calculation is to continue normally.

3

This is not the first call. The calculation is to continue normally, but with a change in input parameters.

NOTE: A preliminary call with tout = t is not counted as a first call here, as no initialization or checking of input is done. (Such a call is sometimes useful for the purpose of outputting the initial condition s .) Thus, the first call for which tout t requires STATUS = 1 on input..

• Output Values for Status

Output Value

Description

1

Nothing occurred. (However, an internal counter was set to detect and prevent repeated calls of this type.)

2

The integration was performed successfully, and no roots were found.

3

The integration was successful, and one or more roots were found.

-1

An excessive amount of work was done on this call, but the integration was otherwise successful. To continue, reset STATUS to a value greater than1 and begin again (the excess work step counter will be reset to 0).

-2

The precision of the machine being used is insufficient for the requested amount of accuracy. Integration was successful. To continue, the tolerance parameters must be reset, and STATUS must be set to 3. (If this condition is detected before taking any steps, then an illegal input return (STATUS = -3) occurs instead.)

-3

Illegal input was detected, before processing any integration steps. If the solver detects an infinite loop of calls to the solver with illegal input, it will cause the run to stop.

-4

There were repeated error test failures on one attempted step, before completing the requested task, but the integration was successful. The problem may have a singularity, or the input may be inappropriate.

-5

There were repeated convergence test failures on one attempted step, before completing the requested task, but the integration was successful. This may be caused by an inaccurate jacobian matrix, if one is being used.

-6

ewt(i) became zero for some i during the integration. Pure relative error control was requested on a variable which has now vanished. Integration was successful.

-7

The length of rwork and/or iwork was too small to proceed, but the integration was successful. This happens when LSODA chooses to switch methods but other variables are too small for the new method.

NOTE: Since the normal output value of STATUS is 2, it does not need to be reset for normal continuation. Also, since a negative input value of STATUS will be regarded as illegal, a negative output value requires the user to change it, and possibly other inputs, before calling the solver again.

### Example

To integrate the example system of differential equations for one time step, H:

H = 0.5; Define the step size.

X = 0.0; Define an initial X value.

Y = [4.0, 6.0]; Define initial Y values.

result = LSODE(Y, X, H, 'differential')
; Integrate over the interval (0, 0.5).

PRINT, result; Print the result.

IDL prints:

3.11523             6.85767

This is the exact solution vector to 5-decimal precision.