ulab.approx
– Numerical approximation methods¶
-
ulab.approx.
bisect
(fun: Callable[[float], float], a: float, b: float, *, xtol: float = 2.4e-07, maxiter: int = 100) → float¶ - Parameters
Find a solution (zero) of the function
f(x)
on the interval (a
..``b``) using the bisection method. The result is accurate to withinxtol
unless more thanmaxiter
steps are required.
-
ulab.approx.
fmin
(fun: Callable[[float], float], x0: float, *, xatol: float = 2.4e-07, fatol: float = 2.4e-07, maxiter: int = 200) → float¶ - Parameters
Find a minimum of the function
f(x)
using the downhill simplex method. The locatedx
is withinfxtol
of the actual minimum, andf(x)
is withinfatol
of the actual minimum unless more thanmaxiter
steps are requried.
-
ulab.approx.
interp
(x: ulab.array, xp: ulab.array, fp: ulab.array, *, left: Optional[float] = None, right: Optional[float] = None) → ulab.array¶ - Parameters
x (ulab.array) – The x-coordinates at which to evaluate the interpolated values.
xp (ulab.array) – The x-coordinates of the data points, must be increasing
fp (ulab.array) – The y-coordinates of the data points, same length as xp
left – Value to return for
x < xp[0]
, default isfp[0]
.right – Value to return for
x > xp[-1]
, default isfp[-1]
.
Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x.
-
ulab.approx.
newton
(fun: Callable[[float], float], x0: float, *, xtol: float = 2.4e-07, rtol: float = 0.0, maxiter: int = 50) → float¶ - Parameters
Find a solution (zero) of the function
f(x)
using Newton’s Method. The result is accurate to withinxtol * rtol * |f(x)|
unless more thanmaxiter
steps are requried.
-
ulab.approx.
trapz
(y: ulab.array, x: Optional[ulab.array] = None, dx: float = 1.0) → float¶ - Parameters
ulab.array y (1D) – the values of the dependent variable
ulab.array x (1D) – optional, the coordinates of the independent variable. Defaults to uniformly spaced values.
dx (float) – the spacing between sample points, if x=None
Returns the integral of y(x) using the trapezoidal rule.