Interpolation.Linear Method

Performs linear interpolation at a single point.

Definition

Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.0.0
C#
public static double Linear(
	double[] xValues,
	double[] yValues,
	double x,
	OutOfRangeMode outOfRangeMode = OutOfRangeMode.Throw,
	double fillValue = NaN
)

Parameters

xValues  Double[]
The x-coordinates of the data points. Must be strictly increasing.
yValues  Double[]
The y-coordinates of the data points.
x  Double
The x-coordinate at which to interpolate.
outOfRangeMode  OutOfRangeMode  (Optional)
Specifies how to handle x-values outside the interpolation range.
fillValue  Double  (Optional)
The value to return when outOfRangeMode is Fill and x is out of range.

Return Value

Double
The interpolated y-value at x.

Remarks

This method performs no allocations and is suitable for single-point evaluation. For repeated evaluations on the same data, consider using PiecewiseLinearCurve(Double[], Double[]) to create a reusable curve object.

The outOfRangeMode parameter controls behavior when x is outside [xValues[0], xValues[n-1]]:

  • Throw: Throws an exception (default).
  • Clamp: Returns the value at the nearest endpoint.
  • Fill: Returns fillValue.

Exceptions

ArgumentNullExceptionxValues or yValues is null.
DimensionMismatchException The lengths of xValues and yValues do not match.
ArgumentExceptionxValues does not have at least 2 elements, or the values in xValues are not strictly increasing.
ArgumentOutOfRangeExceptionx is outside the interpolation range and outOfRangeMode is Throw.

See Also