/// <summary> /// Interpolates linear piecewise between the given points /// this class is a wrapper to provide .NET XML Functions to the MathDotNet Library /// </summary> /// <param name="x">there are the supporting points</param> /// <param name="y">the value at each supporting point. Must have the same length as the x-values</param> public LinearInterpolation(double[] x, double[] y) { //sort the values ascending bool isAscending = false; while (!isAscending) { for (int i = 1; i < x.Length; i++) { if (x[i - 1] > x[i]) //compare whether each value is bigger than the previous { for (int j = 0; j < i; j++) { if (x[j] > x[i]) //if the value at j is bigger than the value at i the correct position was found { //displace the value; List <double> listX = x.ToList(); listX.Remove(x[i]); listX.Insert(j, x[i]); x = listX.ToArray(); List <double> listY = y.ToList(); listY.Remove(y[i]); listY.Insert(j, y[i]); y = listY.ToArray(); break; } } break; } if (x[i - 1].Equals(x[i])) //if a X-value exists twice { throw new ArgumentException("LinearInterpolation: it is forbidden, that a X-value appears twice"); } if (i == x.Length - 1) //if the loop has run to its end { isAscending = true; } } } this._x = x; this._y = y; _spline = LinearSpline.InterpolateInplace(x, y); }