initialize from a grid of points and a c2_function (un-normalized) to an interpolator which, when evaluated with a uniform random variate on [0,1] returns random numbers distributed as the input function. 더 자세히 ...

If derivs is 2, it computes a c2_piecewise_function_p representation of its parent function, which may be a much faster function to use in codes if the parent function is expensive. If xvals and yvals are non-null, it will also fill them in with the function values at each grid point the adaptive algorithm chooses.

If derivs is 1, this does not create the connectors, and returns an null pointer, but will fill in the xvals and yvals vectors with values of the function at points such that the linear interpolation error between the points is bounded by the tolerance values given. Because it uses derivative information from the function to manage the error control, it is almost completely free of issues with missing periods of oscillatory functions, even with no information provided in the sampling grid. This is typically useful for sampling a function for plotting.

If derivs is 0, this does something very like what it does if derivs = 1, but without derivatives. Instead, to compute the intermediate value of the function for error control, it just uses 3-point parabolic interpolation. This is useful amost exclusively for converting a non-c2_function, with no derivatives, but wrapped in a c2_classic_function wrapper, into a table of values to seed an interpolating_function_p. Note, however, that without derivatives, this is very susceptible to missing periods of oscillatory functions, so it is important to set a sampling grid which isn't too much coarser than the typical oscillations.

주의

the sampling_grid of the returned function matches the sampling_grid of its parent.

참고

Adaptive Sampling Examples

매개변수

amin

lower bound of the domain for sampling

amax

upper bound of the domain for sampling

abs_tol

the absolute error bound for each segment

rel_tol

the fractional error bound for each segment.

derivs

if 0 or 1, return a useless function, but fill in the xvals and yvals vectors (if non-null). Also, if 0 or 1, tolerances refer to linear interpolation, not high-order interpolation. If 2, return a full piecewise collection of c2_connector_function_p segments. See discussion above.

[in,out]

xvals

vector of abscissas at which the function was actually sampled (if non-null)

[in,out]

yvals

vector of function values corresponding to xvals (if non-null)

반환값

a new, sampled representation, if derivs is 2. A null pointer if derivs is 0 or 1.

solve f(x)==value very efficiently, with explicit knowledge of derivatives of the function

find_root solves by iterated inverse quadratic extrapolation for a solution to f(x)=y. It includes checks against bad convergence, so it should never be able to fail. Unlike typical secant method or fancier Brent's method finders, this does not depend in any strong wasy on the brackets, unless the finder has to resort to successive approximations to close in on a root. Often, it is possible to make the brackets equal to the domain of the function, if there is any clue as to where the root lies, as given by the parameter start.

매개변수

lower_bracket

the lower bound for the search

upper_bracket

the upper bound for the search. Function sign must be opposite to that at lower_bracket

initialize from a grid of points and a c2_function (un-normalized) to an interpolator which, when evaluated with a uniform random variate on [0,1] returns random numbers distributed as the input function.

solve f(x)=value partial_integrals uses a method with an error O(dx**10) with full information from the derivatives, and falls back to lower order methods if informed of incomplete derivatives. It uses exact midpoint splitting of the intervals for recursion, resulting in no recomputation of the function during recursive descent at previously computed points.

매개변수

xgrid

points between which to evaluate definite integrals.

partials

if non-NULL, a vector in which to receive the partial integrals. It will automatically be sized apprpropriately, if provided, to contain n - 1 elements where n is the length of xgrid

abs_tol

the absolute error bound for each segment

rel_tol

the fractional error bound for each segment. If the error is smaller than either the relative or absolute tolerance, the integration step is finished.

derivs

number of derivatives to trust, which sets the order of the integrator. The order is 3*derivs + 4. derivs can be 0, 1, or 2.

adapt

if true, use recursive adaptation, otherwise do simple evaluation on the grid provided with no error checking.

extrapolate

if true, use simple Richardson extrapolation on the final 2 steps to reduce the error.

반환값

sum of partial integrals, which is the definite integral from the first value in xgrid to the last.

a function without any requirement of valid derivatives to sample into an interpolating function. Very probably a c2_classic_function.

amin

the lower bound of the region to sample

amax

the upper bound of the region to sample

abs_tol

the maximum absolute error permitted when linearly interpolating the points. the real error will be much smaller, since this uses cubic splines at the end.

rel_tol

the maximum relative error permitted when linearly interpolating the points. the real error will be much smaller, since this uses cubic splines at the end.

lowerSlopeNatural

if true, set y'(first point) from 3-point parabola, otherwise compute it from lowerSope

lowerSlope

derivative of the function at the lower bound, used only if lowerSlopeNatural is false

upperSlopeNatural

if true, set y'(last point) from 3-point parabola, otherwise compute it from upperSope

upperSlope

derivative of the function at the upper bound, used only if upperSlopeNatural is false

반환값

the same interpolating function, filled

주의

If the interpolator being filled has a log vertical axis, put the desired relative error in abs_tol, and 0 in rel_tol since the absolute error on the log of a function is the relative error on the function itself.

The sampling grid describes a reasonable initial set of points to look at the function. this should generally be set at a scale which is quite coarse, and sufficient for initializing adaptive integration or possibly root bracketing. For sampling a function to build a new interpolating function, one may want to refine this for accuracy. However, interpolating_functions themselves return their original X grid by default, so refining the grid in this case might be a bad idea.

매개변수

grid

a vector of abscissas. The contents is copied into an internal vector, so the grid can be discarded after passingin.