Note: the current version of
Interpolations supports interpolation evaluation using index calls
, but this feature will be deprecated in future. We highly recommend function calls with
() as follows.
A, construct an "interpolation object"
itp = interpolate(A, options...)
options... (discussed below) controls the type of interpolation you want to perform. This syntax assumes that the samples in
A are equally-spaced.
To evaluate the interpolation at position
(x, y, ...), simply do
v = itp(x, y, ...)
Some interpolation objects support computation of the gradient, which can be obtained as
g = Interpolations.gradient(itp, x, y, ...)
Interpolations.gradient!(g, itp, x, y, ...)
g is a pre-allocated vector.
Some interpolation objects support computation of the hessian, which can be obtained as
h = Interpolations.hessian(itp, x, y, ...)
Interpolations.hessian!(h, itp, x, y, ...)
h is a pre-allocated matrix.
A may have any element type that supports the operations of addition and multiplication. Examples include scalars like
Rational, but also multi-valued types like
RGB color vectors.
(x, y, ...) are n-tuples of numbers. Typically these will be real-valued (not necessarily integer-valued), but can also be of types such as DualNumbers if you want to verify the computed value of gradients. (Alternatively, verify gradients using ForwardDiff.) You can also use Julia's iterator objects, e.g.,
function ongrid!(dest, itp) for I in CartesianIndices(itp) dest[I] = itp(I) end end
would store the on-grid value at each grid point of
itp in the output
dest. Finally, courtesy of Julia's indexing rules, you can also use
fine = itp(range(1,stop=10,length=1001), range(1,stop=15,length=201))
There is also an abbreviated Convenience notation.