public class LinearInterpolation extends Object implements Interpolation
Supply at least two data points with distinct x coordinates.
SortedOrderedPairs provides an
ordered representation. fit returns a function to evaluate at
new x values. Outside the observed x range the nearest segment is
extrapolated; values are not clamped to an endpoint.
import dev.nm.analysis.curvefit.interpolation.univariate.LinearInterpolation;
import dev.nm.analysis.function.rn2r1.univariate.UnivariateRealFunction;
import dev.nm.analysis.function.tuple.SortedOrderedPairs;
SortedOrderedPairs points = new SortedOrderedPairs(
new double[]{0, 1, 2}, new double[]{0, 2, 4});
UnivariateRealFunction curve = new LinearInterpolation().fit(points);
assert Math.abs(curve.evaluate(0.5) - 1.0) < 1e-12;
assert Math.abs(curve.evaluate(3.0) - 6.0) < 1e-12; // extrapolation
| Constructor and Description |
|---|
LinearInterpolation() |
| Modifier and Type | Method and Description |
|---|---|
UnivariateRealFunction |
fit(OrderedPairs f)
Fit a real valued function from a discrete set of data points.
|
public UnivariateRealFunction fit(OrderedPairs f)
Interpolationfit in interface CurveFittingfit in interface Interpolationf - a discrete set of data pointsCopyright © 2010-2026 NM Group. All Rights Reserved.