/// <summary> /// Create a linear spline interpolation from an unsorted set of (x,y) value pairs. /// WARNING: Works in-place and can thus causes the data array to be reordered and modified. /// </summary> public static TransformedInterpolation InterpolateInplace( Func <double, double> transform, Func <double, double> transformInverse, double[] x, double[] y) { if (x.Length != y.Length) { throw new ArgumentException("All vectors must have the same dimensionality."); } Sorting.Sort(x, y); CommonParallel.For(0, y.Length, 4096, (a, b) => { for (int i = a; i < b; i++) { y[i] = transformInverse(y[i]); } }); return(new TransformedInterpolation(LinearSpline.InterpolateSorted(x, y), transform)); }
/// <summary> /// Create a linear spline interpolation from a set of (x,y) value pairs, sorted ascendingly by x. /// </summary> public static TransformedInterpolation InterpolateSorted( Func <double, double> transform, Func <double, double> transformInverse, double[] x, double[] y) { if (x.Length != y.Length) { throw new ArgumentException(Resource.ArgumentVectorsSameLength); } var yhat = new double[y.Length]; CommonParallel.For(0, y.Length, 4096, (a, b) => { for (int i = a; i < b; i++) { yhat[i] = transformInverse(y[i]); } }); return(new TransformedInterpolation(LinearSpline.InterpolateSorted(x, yhat), transform)); }
/// <param name="x">Sample points (N), sorted ascending</param> /// <param name="logy">Natural logarithm of the sample values (N) at the corresponding points</param> public LogLinear(double[] x, double[] logy) { _spline = LinearSpline.InterpolateSorted(x, logy); }