anaflow.tools.laplace¶
Anaflow subpackage providing functions concerning the laplace transformation.
The following functions are provided

Callable Laplace transform. 

Callable Laplace inversion. 

The laplace transform. 

The stehfestalgorithm 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 timevariable:
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
orNone
, optional) – Keywordarguments given as a dictionary that are forwarded to the function given infunc
. Will be merged with**kwargs
This is designed for overlapping keywords. Default:None
**kwargs – Keywordarguments that are forwarded to the function given in
func
. Will be merged witharg_dict
.
 Returns
The Laplace transformed of the given function.
 Return type
 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 laplacespace that shall be inverted. The first argument needs to be the laplacevariable:
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
orNone
, optional) – Keyword arguments for the used method.arg_dict (
dict
orNone
, optional) – Keywordarguments given as a dictionary that are forwarded to the function given infunc
. Will be merged with**kwargs
This is designed for overlapping keywords. Default:None
**kwargs – Keywordarguments that are forwarded to the function given in
func
. Will be merged witharg_dict
.
 Returns
The Laplace inverse of the given function.
 Return type
 Raises
ValueError – If func is not callable.
ValueError – If method is unknown.
 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 timevariable:
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
ornumpy.ndarray
) – phasepoints to evaluate the transformed function atarg_dict (
dict
orNone
, optional) – Keywordarguments given as a dictionary that are forwarded to the function given infunc
. Will be merged with**kwargs
This is designed for overlapping keywords instehfest
andfunc
.Default:None
**kwargs – Keywordarguments that are forwarded to the function given in
func
. Will be merged witharg_dict
 Returns
Array with all evaluations in phasespace.
 Return type
 Raises
ValueError – If func is not callable.
 stehfest(func, time, bound=12, arg_dict=None, **kwargs)[source]¶
The stehfestalgorithm for numerical laplace inversion.
The Inversion was derivide in ‘’Stehfest 1970’’[R1] and is given by the formula
In the algorithm corresponds to
bound
, tofunc
and totime
. Parameters
func (
callable
) –function in laplacespace that shall be inverted. The first argument needs to be the laplacevariable:
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
ornumpy.ndarray
) – timepoints to evaluate the function atbound (
int
, optional) – Here you can specify the number of interations within this algorithm. Default:12
arg_dict (
dict
orNone
, optional) – Keywordarguments given as a dictionary that are forwarded to the function given infunc
. Will be merged with**kwargs
This is designed for overlapping keywords instehfest
andfunc
.Default:None
**kwargs – Keywordarguments that are forwarded to the function given in
func
. Will be merged witharg_dict
 Returns
Array with all evaluations in Timespace.
 Return type
 Raises
ValueError – If func is not callable.
ValueError – If time is not positive.
ValueError – If bound is not positive.
ValueError – If bound is not even.
References
 R1
Stehfest, H., ‘’Algorithm 368: Numerical inversion of laplace transforms [d5].’’ Communications of the ACM, 13(1):4749, 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.])