anaflow.tools.laplace

Anaflow subpackage providing functions concerning the laplace transformation.

The following functions are provided

get_lap(func[, arg_dict]) Callable Laplace transform.
get_lap_inv(func[, method, method_dict, …]) Callable Laplace inversion.
lap_trans(func, phase[, arg_dict]) The laplace transform.
stehfest(func, time[, bound, arg_dict]) The stehfest-algorithm for numerical laplace inversion.
get_lap(func, arg_dict=None, **kwargs)[source]

Callable Laplace transform.

Get the Laplace transform of a given function as a callable function.

Parameters:
  • func (callable) –

    function that shall be transformed. The first argument needs to be the time-variable: func(t, **kwargs)

    func should be capable of taking numpy arrays as input for s and the first shape component of the output of func should match the shape of s.

  • arg_dict (dict or None, optional) – Keyword-arguments given as a dictionary that are forwarded to the function given in func. Will be merged with **kwargs This is designed for overlapping keywords. Default: None
  • **kwargs – Keyword-arguments that are forwarded to the function given in func. Will be merged with arg_dict.
Returns:

The Laplace transformed of the given function.

Return type:

callable

Raises:

ValueError – If func is not callable.

lap_trans(func, phase, arg_dict=None, **kwargs)[source]

The laplace transform.

Parameters:
  • func (callable) –

    function that shall be transformed. The first argument needs to be the time-variable: func(s, **kwargs)

    func should be capable of taking numpy arrays as input for s and the first shape component of the output of func should match the shape of s.

  • phase (float or numpy.ndarray) – phase-points to evaluate the transformed function at
  • arg_dict (dict or None, optional) – Keyword-arguments given as a dictionary that are forwarded to the function given in func. Will be merged with **kwargs This is designed for overlapping keywords in stehfest and func.Default: None
  • **kwargs – Keyword-arguments that are forwarded to the function given in func. Will be merged with arg_dict
Returns:

Array with all evaluations in phase-space.

Return type:

numpy.ndarray

Raises:

ValueError – If func is not callable.

get_lap_inv(func, method='stehfest', method_dict=None, arg_dict=None, **kwargs)[source]

Callable Laplace inversion.

Get the Laplace inversion of a given function as a callable function.

Parameters:
  • func (callable) –

    function in laplace-space that shall be inverted. The first argument needs to be the laplace-variable: func(s, **kwargs)

    func should be capable of taking numpy arrays as input for s and the first shape component of the output of func should match the shape of s.

  • method (str) –

    Method that should be used to calculate the inverse. One can choose between

    • "stehfest": for the stehfest algorithm

    Default: "stehfest"

  • method_dict (dict or None, optional) – Keyword arguments for the used method.
  • arg_dict (dict or None, optional) – Keyword-arguments given as a dictionary that are forwarded to the function given in func. Will be merged with **kwargs This is designed for overlapping keywords. Default: None
  • **kwargs – Keyword-arguments that are forwarded to the function given in func. Will be merged with arg_dict.
Returns:

The Laplace inverse of the given function.

Return type:

callable

Raises:
stehfest(func, time, bound=12, arg_dict=None, **kwargs)[source]

The stehfest-algorithm for numerical laplace inversion.

The Inversion was derivide in ‘’Stehfest 1970’‘[R1] and is given by the formula

f\left(t\right) &=\frac{\ln2}{t}\sum_{n=1}^{N}c_{n}\cdot\tilde{f}
\left(n\cdot\frac{\ln2}{t}\right)\\
c_{n} &=\left(-1\right)^{n+\frac{N}{2}}\cdot
\sum_{k=\left\lfloor \frac{n+1}{2}\right\rfloor }
^{\min\left\{ n,\frac{N}{2}\right\} }
\frac{k^{\frac{N}{2}+1}\cdot\binom{2k}{k}}
{\left(\frac{N}{2}-k\right)!\cdot\left(n-k\right)!
\cdot\left(2k-n\right)!}

In the algorithm N corresponds to bound, \tilde{f} to func and t to time.

Parameters:
  • func (callable) –

    function in laplace-space that shall be inverted. The first argument needs to be the laplace-variable: func(s, **kwargs)

    func should be capable of taking numpy arrays as input for s and the first shape component of the output of func should match the shape of s.

  • time (float or numpy.ndarray) – time-points to evaluate the function at
  • bound (int, optional) – Here you can specify the number of interations within this algorithm. Default: 12
  • arg_dict (dict or None, optional) – Keyword-arguments given as a dictionary that are forwarded to the function given in func. Will be merged with **kwargs This is designed for overlapping keywords in stehfest and func.Default: None
  • **kwargs – Keyword-arguments that are forwarded to the function given in func. Will be merged with arg_dict
Returns:

Array with all evaluations in Time-space.

Return type:

numpy.ndarray

Raises:

References

[R1]Stehfest, H., ‘’Algorithm 368: Numerical inversion of laplace transforms [d5].’’ Communications of the ACM, 13(1):47-49, 1970

Notes

The parameter time needs to be strictly positiv.

The algorithm gets unstable for bound values above 20.

Examples

>>> f = lambda x: x**-1
>>> stehfest(f, [1,10,100])
array([ 1.,  1.,  1.])