API

Here we write all the methods defined in AdaptiveStepSize.jl, both public and private, since Documenter will complain if the private ones are not included. Use those at your own risk and do not expect consistency between versions in private methods.

AdaptiveStepSize.AdaptiveStepSizeModule

Main module for AdaptiveStepSize.jl, a Julia package used to obtain the minimum amount of points needed for the interpolation of a function in the given interval within the desired tolerance.

Only linear interpolation methods are implemented for now. Any contribution is wecolmed to further implement other methods.

Check the docs for more information.

source
AdaptiveStepSize.points_linearMethod
points_linear(f, domain, tol::T; scan_step = (domain[end] - domain[begin]) / 100) where T <: Real

Computes points used for a linear interpolation of the function f in the given domain within a tolerance tol.

See also points_linear_singular for managing singular points.

Arguments

  • f: The function used for the linear interpolation. It must be of the form of f(x), where x is a number.
  • domain: a tuple or array representing the interpolation domain, e.g., the tuple (a, b).
  • tol::T where T <: Real: the desired tolerance of the points. The real value of the function at any point xᵢ minus the aproximation will be smaller than tol, i.e., |f(xᵢ) - yᵢ| < tol.

Keywords

  • scan_step: Minimum step size that will be used to scan the whole domain. The returned points will have at least a spacing of scan_step. Very small values will produce a very long execution time. By default it will divide the domain in 100 intervals.

Returns

  • (xs, ys): A tuple containing two arrays of points, xs for the independent variable and ys for the computed values of the function.

Notes

The function f must have a continuous second derivative in order to compute the linear interpolation error. This second derivative is computed using Enzyme's automatic differentiation.

If the returned (xs, ys) contains just the endpoints, try decreasing the scan_step size and/or increasing the tolerance tol.

If the execution time of a single call to the function f is quite long, this adaptive method might not be suitable.

source
AdaptiveStepSize.points_linear_singularMethod
points_linear_singular(f, domain, singularities::Vector{T}, tol::T; scan_step = (domain[end] - domain[begin]) / 100) where T <: Real

Computes points used for a linear interpolation of the function f in the given domain within a tolerance tol. Manages singular points though the array singularities.

See points_linear for an in depth description of the arguments. This function needs the additional argument singularities. This must be a Vector{T} where T<:Real that contains each singular point.

A singularity in this case is a point at which the function is not well-behaved, like abs(x) at x = 0, where the function is continuous but not differentiable.

If the function has several singularities, we can write those in the singularities vector. The function points_linear will be applied at each subinterval. In addition, the second derivative will never be computed at those endpoints, i.e., at the singularities and the domain points. Note that f will be evaluated at the endpoints and it should handle those discontinuities properly. It is the user responsability to do so.

Notes

If you have a piecewise function, it might be convenient to apply points_linear at each interval of the function, instead of passing the singularities vector here. The reason is that the result contains just one big pair xs and ys vectors and it is not aware of the points where piecewise function is not continuous, hence producing undesiderable results in the interpolation.

The safest bet here is linearly interpolate each region of the piecewise function separately.

source