Beispiel #1
0
        /// <summary>
        /// Initializes a new polynomial that passes through the given points.
        /// </summary>
        /// <param name="points">An N X 2 array whose first column contains the x values of points and whose second column contains the corresponding y values.</param>
        /// <returns>A polynomial of degree N-1 that passes through all the given points.</returns>
        public static Polynomial FromPoints(double[,] points)
        {
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }
            if (points.GetLength(0) == 0)
            {
                throw new ArgumentException("The first dimension of the points array must have length at least one.", nameof(points));
            }
            if (points.GetLength(1) != 2)
            {
                throw new ArgumentException("The second dimension of the points array must have length two.", nameof(points));
            }
            double[] x = new double[points.GetLength(0)];
            double[] y = new double[points.GetLength(0)];
            for (int i = 0; i < points.GetLength(0); i++)
            {
                x[i] = points[i, 0];
                y[i] = points[i, 1];
            }
            PolynomialInterpolator interpolator = new PolynomialInterpolator(x, y);

            return(new InterpolatingPolynomial(interpolator));
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new polynomial that passes through the given points.
        /// </summary>
        /// <param name="points">A collection of points.</param>
        /// <returns>A polynomial that passes through all the given points.</returns>
        public static Polynomial FromPoints(ICollection <XY> points)
        {
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }
            if (points.Count == 0)
            {
                throw new ArgumentException("There must be at least one point in the points collection.", nameof(points));
            }
            double[] x = new double[points.Count];
            double[] y = new double[points.Count];
            int      i = 0;

            foreach (XY point in points)
            {
                x[i] = point.X;
                y[i] = point.Y;
                i++;
            }
            PolynomialInterpolator interpolator = new PolynomialInterpolator(x, y);

            return(new InterpolatingPolynomial(interpolator));
        }
 internal InterpolatingPolynomial(PolynomialInterpolator interpolator) : base(interpolator.GetCoefficients())
 {
     this.interpolator = interpolator;
 }
 internal InterpolatingPolynomial(PolynomialInterpolator interpolator)
     : base(interpolator.GetCoefficients())
 {
     this.interpolator = interpolator;
 }
Beispiel #5
0
 /// <summary>
 /// Initializes a new polynomial that passes through the given points.
 /// </summary>
 /// <param name="points">A collection of points.</param>
 /// <returns>A polynomial that passes through all the given points.</returns>
 public static Polynomial FromPoints(ICollection<XY> points)
 {
     if (points == null) throw new ArgumentNullException("points");
     if (points.Count == 0) throw new ArgumentException("There must be at least one point in the points collection.", "points");
     double[] x = new double[points.Count];
     double[] y = new double[points.Count];
     int i = 0;
     foreach (XY point in points) {
         x[i] = point.X;
         y[i] = point.Y;
         i++;
     }
     PolynomialInterpolator interpolator = new PolynomialInterpolator(x, y);
     return (new InterpolatingPolynomial(interpolator));
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new polynomial that passes through the given points.
 /// </summary>
 /// <param name="points">An N X 2 array whose first column contains the x values of points and whose second column contains the corresponding y values.</param>
 /// <returns>A polynomial of degree N-1 that passes through all the given points.</returns>
 public static Polynomial FromPoints(double[,] points)
 {
     if (points == null) throw new ArgumentNullException("points");
     if (points.GetLength(0) == 0) throw new ArgumentException("The first dimension of the points array must have length at least one.", "points");
     if (points.GetLength(1) != 2) throw new ArgumentException("The second dimension of the points array must have length two.", "points");
     double[] x = new double[points.GetLength(0)];
     double[] y = new double[points.GetLength(0)];
     for (int i = 0; i < points.GetLength(0); i++) {
         x[i] = points[i, 0];
         y[i] = points[i, 1];
     }
     PolynomialInterpolator interpolator = new PolynomialInterpolator(x, y);
     return (new InterpolatingPolynomial(interpolator));
 }