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:
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 ofpv_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 byget_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 [0] element is the coeffiecient of \(x_{n+1}\) (scalar),
- the [1] element is the matrix of constant terms of shape
(Nx1)
of \(x_{n+1}\), - the [2] element is the coefficient of the LTE of \(x_{n+1}\) (scalar),
- the [3] element is the predicted value of \(x_{n+1}\) (matrix), only
available if the
predict
parameter is set toTrue
. Otherwise it’sNone
. - the [4] element is the coefficient of the LTE of the prediction (matrix),
also only available if the
predict
parameter is set toTrue
, otherwise, it isNone
.
Note
With the returned values, the derivative may then be written as:
\[\frac{dx_{n+1}}{dt} = \mathrm{ret[0]}\; x_{n+1} + \mathrm{ret[1]}\]
-
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 toNone
.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 tomax_order_of_dx
, but it regards \(dx/dt\) instead of \(x\).If
max_order_of_x
ormax_order_of_dx
are set toNone
, 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))
-
order
= 1¶ The order of the differentiation formula