# ahkab.implicit_euler¶

This module implements the Implicit Euler (IE, aka Backward Euler, BE) and a first-order forward formula (FF) to be used for prediction.

The formula is:

$x'_{n+1} = C_0 x_{n+1} + C_1 x_{n}$

Where:

• $$C_0 = 1/h$$
• $$C_1 = -1/h$$

The backward Euler method is not only A-stable, making it suitable for the solution of stiff equations but is even L-stable.

## Module reference¶

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

Get the coefficients for the DF, FF and LTE calculation

Parameters:

pv_array : list

It must be an list of lists, each of them having the structure [time, xnk, dxnk].

In particular, the pv_array[k] element of pv_array is composed of:

• time, float, which is the time at which the solution is valid: t(n-k),
• xnk, ndarray, which is $$x_{n-k}$$,
• dxnk, ndarray, $$dx_{n-k}/dt$$.

The length of pv_array has to match the value returned by get_required_values().

Any values that are not needed may be set to None, and they will be disregarded.

suggested_step : float
The step that is (expected) to be used in the DF. It is only an expectation because it may be rejected at a later stage if there is step control enabled.
predict : boolean, optional
Whether the terms for a prediction formula are required as well or not. Defaults to True.

Returns:

ret : tuple

ret is a tuple of 5 elements, where:

• the  element is the coeffiecient of $$x_{n+1}$$ (scalar),
• the  element is the matrix of constant terms of shape (Nx1) of $$x_{n+1}$$,
• the  element is the coefficient of the LTE of $$x_{n+1}$$ (scalar),
• the  element is the predicted value of $$x_{n+1}$$ (matrix), only available if the predict parameter is set to True. Otherwise it’s None.
• the  element is the coefficient of the LTE of the prediction (matrix), also only available if the predict parameter is set to True, otherwise, it is None.

Note

With the returned values, the derivative may then be written as:

$\frac{dx_{n+1}}{dt} = \mathrm{ret}\; x_{n+1} + \mathrm{ret}$
get_df_coeff(step)[source]

Get the coefficients for a Backward Euler differentiation step

The first coefficient is the factor for the new point $$x_{n+1}$$, the second is the one for the previous point $$x_{n}$$.

If the step value is $$h$$, this method returns:

$[1/h, -1/h]$

Parameters:

step : float
The differentiation formula step value.

Returns:

c0, c1 : floats
The coefficients of $$x_{n+1}$$ and $$x_{n}$$.
get_required_values()[source]

Get what values are required by the DF and the FF

Returns

The method returns two tuples, each of them having the form:

[max_order_of_x, max_order_of_dx]

The first tuple is the one to be considered if no Forward Formula (FF) is needed, the second if the FF is also required.

Both the values in each tuple can be either of type int or be set to None.

If max_order_of_x is set to an arbitrary positive integer value $$k$$, the Differentiation Formula (DF) needs all the $$x_{n-i}$$ values of $$x$$, where $$i \le k$$ (the value x has $$i+1$$ steps before the one we will ask for the derivative). The same applies to max_order_of_dx, but it regards $$dx/dt$$ instead of $$x$$.

If max_order_of_x or max_order_of_dx are set to None, that means that no value of $$x$$, or $$dx/dt$$, is required.

In the case at hand, where the formula is the Backward Euler (BE, aka Implicit Euler, IE), this method will return:

((0, None), (1, None))

has_ff()[source]

Is a forward formula for prediction available?

Returns:

True

is_implicit()[source]

Is this differentiation formula implicit?

order = 1

The order of the differentiation formula