This file implements the Trapezoidal (TRAP) Differentiation Formula (DF) and a second order prediction formula.

Module reference

get_df(pv_array, suggested_step, predict=True)[source]

Get the coefficients for DF and prediction formula


pv_array : sequence of sequences

Each element of pv_array must be of the form:

(time, x, derivate(x))

In particular, the \(k\) element of pv_array contains the values of:

  • \(t_{n-k}\) (the time),
  • \(x_{n-k}\),
  • \(dx_{n-k}/dt\)

evaluated \(k\) time steps before the current one, labeled \(n+1\).

How many samples are necessary is given by ahkab.trap.get_required_values().

Values that are not needed may be set to None, as they will be disregarded.

suggested_step : float
The step that will be used for the current iteration, provided the error will be deemed acceptable.
predict : bool, optional
Whether a prediction for \(x_n\) is needed as well or not. Defaults to True.


ret : tuple

The return value has the form:

(C1, C0, x_lte_coeff, predict_x, predict_lte_coeff)

The derivative may be written as:

\[d(x(n+1))/dt = C1 x(n+1) + C0\]

x_lte_coeff is the coefficient of the Local Truncation Error, predict_x is the predicted value for \(x\) and predict_lte_coeff is the LTE coefficient for the prediction.

Raises:ValueError – if the pv_array is malformed.

Get info regarding what values are needed by the DF


tpl : tuple of tuples

A tuple of two tuples.

  • The first tuple indicates what past values of the unknown are needed for the DF.
  • The second tuple indicates what past values of the unknown are needed for the prediction method.

In particular, each of the sub-tuples is built this way:

(max_order_of_x, max_order_of_dx)

Where both the values are either int, or None. If max_order_of_x is set to an integer value \(k\), the DF needs all the \(x_{n-i}\) values of x, for all \(0 \le i \le k\). In the previous text, \(x_{n-i}\) is the value the \(x\) array assumed \(i\) steps before the one we are considering for the derivative.

Similar considerations apply to max_order_of_dx, but regard rather \(dx_n/dt\) instead of \(x_n\).

If any of the values is set to None, it is to be assume that no value is required.

The first array has to be used if no prediction is required, the second are the values needed for prediction.


Has the method a Forward Formula for prediction?


doesit : bool
In this particular case, this function always returns True.

Is this Differentiation Formula (DF) implicit?


isit : boolean
In this case, that’s True.