API
- class idesolver.IDESolver(x: ~numpy.ndarray, y_0: float | ~numpy.float64 | complex | ~numpy.complex128 | ~numpy.ndarray | list, c: ~typing.Callable | None = None, d: ~typing.Callable | None = None, k: ~typing.Callable | None = None, f: ~typing.Callable | None = None, lower_bound: ~typing.Callable | None = None, upper_bound: ~typing.Callable | None = None, global_error_tolerance: float = 1e-06, max_iterations: int | None = None, ode_method: str = 'RK45', ode_atol: float = 1e-08, ode_rtol: float = 1e-08, int_atol: float = 1e-08, int_rtol: float = 1e-08, interpolation_kind: str = 'cubic', smoothing_factor: float = 0.5, store_intermediate_y: bool = False, global_error_function: ~typing.Callable = <function global_error>)[source]
A class that handles solving an integro-differential equation of the form
\[\begin{split}\frac{dy}{dx} & = c(y, x) + d(x) \int_{\alpha(x)}^{\beta(x)} k(x, s) \, F( y(s) ) \, ds, \\ & x \in [a, b], \quad y(a) = y_0.\end{split}\]- x
The positions where the solution is calculated (i.e., where \(y\) is evaluated).
- Type:
- y
The solution \(y(x)\).
None
untilIDESolver.solve()
is finished.- Type:
- global_error
The final global error estimate.
None
untilIDESolver.solve()
is finished.- Type:
- iteration
The current iteration.
None
untilIDESolver.solve()
starts.- Type:
- y_intermediate
The intermediate solutions. Only exists if
store_intermediate_y
isTrue
.
- Parameters:
x (
numpy.ndarray
) – The array of \(x\) values to find the solution \(y(x)\) at. Generally something likenumpy.linspace(a, b, num_pts)
.y_0 (
float
orcomplex
ornumpy.ndarray
) – The initial condition, \(y_0 = y(a)\) (can be multidimensional).c – The function \(c(y, x)\). Defaults to \(c(y, x) = 0\).
d – The function \(d(x)\). Defaults to \(d(x) = 1\).
k – The kernel function \(k(x, s)\). Defaults to \(k(x, s) = 1\).
f – The function \(F(y)\). Defaults to \(f(y) = 0\).
lower_bound – The lower bound function \(\alpha(x)\). Defaults to the first element of
x
.upper_bound – The upper bound function \(\beta(x)\). Defaults to the last element of
x
.global_error_tolerance (
float
) – The algorithm will continue until the global errors goes below this or uses more than max_iterations iterations. IfNone
, the algorithm continues until hitting max_iterations.max_iterations (
int
) – The maximum number of iterations to use. IfNone
, iteration will not stop unless the global_error_tolerance is satisfied. Defaults toNone
.ode_method (
str
) – The ODE solution method to use. As the method option ofscipy.integrate.solve_ivp()
. Defaults to'RK45'
, which is good for non-stiff systems.ode_atol (
float
) – The absolute tolerance for the ODE solver. As the atol argument ofscipy.integrate.solve_ivp()
.ode_rtol (
float
) – The relative tolerance for the ODE solver. As the rtol argument ofscipy.integrate.solve_ivp()
.int_atol (
float
) – The absolute tolerance for the integration routine. As the epsabs argument ofscipy.integrate.quad()
.int_rtol (
float
) – The relative tolerance for the integration routine. As the epsrel argument ofscipy.integrate.quad()
.interpolation_kind (
str
) – The type of interpolation to use. As the kind argument ofscipy.interpolate.interp1d
. Defaults to'cubic'
.smoothing_factor (
float
) – The smoothing factor used to combine the current guess with the new guess at each iteration. Defaults to0.5
.store_intermediate_y (
bool
) – IfTrue
, the intermediate guesses for \(y(x)\) at each iteration will be stored in the attribute y_intermediate.global_error_function – The function to use to calculate the global error. Defaults to
global_error()
.
- solve(callback: Callable | None = None) ndarray [source]
Compute the solution to the IDE.
Will emit a warning message if the global error increases on an iteration. This does not necessarily mean that the algorithm is not converging, but may indicate that it’s having problems.
Will emit a warning message if the maximum number of iterations is used without reaching the global error tolerance.
- Parameters:
callback – A function to call after each iteration. The function is passed the
IDESolver
instance, the current \(y\) guess, and the current global error.- Returns:
The solution to the IDE (i.e., \(y(x)\)).
- Return type:
- idesolver.global_error(y1: ndarray, y2: ndarray) float [source]
The default global error function.
The estimate is the square root of the sum of squared differences between y1 and y2.
- Parameters:
y1 (
numpy.ndarray
) – A guess of the solution.y2 (
numpy.ndarray
) – Another guess of the solution.
- Returns:
error – The global error estimate between y1 and y2.
- Return type:
- idesolver.complex_quad(integrand: ~typing.Callable, lower_bound: float, upper_bound: float, **kwargs) -> (<class 'complex'>, <class 'float'>, <class 'float'>, <class 'tuple'>, <class 'tuple'>)[source]
A thin wrapper over
scipy.integrate.quad()
that handles splitting the real and complex parts of the integral and recombining them. Keyword arguments are passed to both of the internalquad
calls.