Interpolation.InverseLinear Method

Definition

Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.0.0

Overload List

InverseLinear(Double[], Double[], Double) Performs inverse linear interpolation to find the x-coordinate for a given y-value.
InverseLinear(ReadOnlySpan<Double>, ReadOnlySpan<Double>, Double, OutOfRangeMode) Performs inverse linear interpolation to find the x-coordinate for a given y-value.

InverseLinear(Double[], Double[], Double)

Performs inverse linear interpolation to find the x-coordinate for a given y-value.
C#
public static double InverseLinear(
	double[] xValues,
	double[] yValues,
	double y
)

Parameters

xValues  Double[]
The x-coordinates of the data points. Must be strictly increasing.
yValues  Double[]
The y-coordinates of the data points. Must be strictly monotone (increasing or decreasing).
y  Double
The y-coordinate for which to find the corresponding x-coordinate.

Return Value

Double
The x-coordinate corresponding to the y-value y.

Remarks

This method performs the inverse operation of linear interpolation: given a y-value, it finds the corresponding x-value. This method requires yValues to be strictly monotone (either all increasing or all decreasing) to ensure a unique solution. The monotonicity direction is detected automatically.

For non-monotone data where multiple solutions may exist, use InverseLinearBefore(Double[], Double[], Double, Double), InverseLinearAfter(Double[], Double[], Double, Double), or InverseLinearNear(Double[], Double[], Double, Double) to select among multiple solutions.

This method uses binary search for optimal performance and makes no allocations.

Exceptions

ArgumentNullExceptionxValues or yValues is null.
DimensionMismatchException The lengths of xValues and yValues do not match.
ArgumentExceptionxValues does not have at least 2 elements, the values in xValues are not strictly increasing, or yValues is not strictly monotone (increasing or decreasing).
ArgumentOutOfRangeExceptiony is outside the range [min(yValues), max(yValues)].

InverseLinear(ReadOnlySpan<Double>, ReadOnlySpan<Double>, Double, OutOfRangeMode)

Performs inverse linear interpolation to find the x-coordinate for a given y-value.
C#
public static double InverseLinear(
	ReadOnlySpan<double> xValues,
	ReadOnlySpan<double> yValues,
	double y,
	OutOfRangeMode outOfRange = OutOfRangeMode.Clamp
)

Parameters

xValues  ReadOnlySpan<Double>
The x-coordinates of the data points. Must be strictly increasing.
yValues  ReadOnlySpan<Double>
The y-coordinates of the data points. Must be strictly monotone (increasing or decreasing).
y  Double
The y-coordinate for which to find the corresponding x-coordinate.
outOfRange  OutOfRangeMode  (Optional)
 

Return Value

Double
The x-coordinate corresponding to the y-value y.

Remarks

This method performs the inverse operation of linear interpolation: given a y-value, it finds the corresponding x-value. This method requires yValues to be strictly monotone (either all increasing or all decreasing) to ensure a unique solution. The monotonicity direction is detected automatically.

For non-monotone data where multiple solutions may exist, use InverseLinearBefore(ReadOnlySpan<Double>, ReadOnlySpan<Double>, Double, Double), InverseLinearAfter(ReadOnlySpan<Double>, ReadOnlySpan<Double>, Double, Double), or InverseLinearNear(ReadOnlySpan<Double>, ReadOnlySpan<Double>, Double, Double) to select among multiple solutions.

This method uses binary search for optimal performance and makes no allocations.

Exceptions

ArgumentNullExceptionxValues or yValues is null.
DimensionMismatchException The lengths of xValues and yValues do not match.
ArgumentExceptionxValues does not have at least 2 elements, the values in xValues are not strictly increasing, or yValues is not strictly monotone (increasing or decreasing).
ArgumentOutOfRangeExceptiony is outside the range [min(yValues), max(yValues)].

See Also