change to lists

This commit is contained in:
CWX
2025-01-17 23:02:20 +00:00
parent 2b82a1065f
commit 12a5a27809
+2 -2
View File
@@ -91,14 +91,14 @@ public class MathUtil
/// <param name="x">Support points in x (of same length as y)</param>
/// <param name="y">Support points in y (of same length as x)</param>
/// <returns>Interpolated value at xp, or null if xp is out of bounds</returns>
public static double? Interp1(double xp, double[] x, double[] y)
public double? Interp1(double xp, List<double> x, List<double> y)
{
if (xp > x[^1]) // ^1 is the last index in C#
return y[^1];
if (xp < x[0]) return y[0];
for (var i = 0; i < x.Length - 1; i++)
for (var i = 0; i < x.Count - 1; i++)
if (xp >= x[i] && xp <= x[i + 1])
return y[i] + (xp - x[i]) * (y[i + 1] - y[i]) / (x[i + 1] - x[i]);