Esempio n. 1
0
        CreateNaturalCubicSpline(
            IList <double> points,
            IList <double> values
            )
        {
            CubicSplineInterpolation method = new CubicSplineInterpolation();

            method.Init(
                points,
                values
                );
            return(method);
        }
Esempio n. 2
0
        CreateCubicSpline(
            IList <double> points,
            IList <double> values,
            SplineBoundaryCondition leftBoundaryCondition,
            double leftBoundary,
            SplineBoundaryCondition rightBoundaryCondition,
            double rightBoundary
            )
        {
            CubicSplineInterpolation method = new CubicSplineInterpolation();

            method.Init(
                points,
                values,
                leftBoundaryCondition,
                leftBoundary,
                rightBoundaryCondition,
                rightBoundary
                );
            return(method);
        }
Esempio n. 3
0
        private static void checkSplines(Commons.SplineBox spline, Chart chart)
        {
            spline.dict   = new Dictionary <double, double>();
            Commons.xlist = Commons.X.ToList <double>();
            Commons.ylist = Commons.Y.ToList <double>();

            double step = 0.3;

            if (spline.POWER == 1)
            {
                spline.dict = new Dictionary <double, double>();
                LinearSplineInterpolation splineInterpol = new LinearSplineInterpolation();
                splineInterpol.Init(Commons.xlist, Commons.ylist);
                for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
                {
                    // spline.listX.Add(i);
                    spline.dict.Add(i, splineInterpol.Interpolate(i));
                    //spline.listY.Add(splineInterpol.Interpolate(i));
                }
            }
            else if (spline.POWER == 2)
            {
                spline.dict = new Dictionary <double, double>();

                QuadraticSpline quadraticSplineInterpol = new QuadraticSpline();
                quadraticSplineInterpol.Init(Commons.xlist, Commons.ylist);
                for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
                {
                    //spline.listX.Add(i);
                    //spline.listY.Add(quadraticSplineInterpol.Interpolate(i));
                    spline.dict.Add(i, quadraticSplineInterpol.Interpolate(i));
                }
            }
            else if (spline.POWER > 2 && spline.POWER < 5)
            {
                spline.dict = new Dictionary <double, double>();

                CubicSplineInterpolation cubicSplineInterpol = new CubicSplineInterpolation();
                cubicSplineInterpol.Init(Commons.xlist, Commons.ylist);
                for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
                {
                    //spline.listX.Add(i);
                    //spline.listY.Add(cubicSplineInterpol.Interpolate(i));
                    spline.dict.Add(i, cubicSplineInterpol.Interpolate(i));
                }
            }
            else if (spline.POWER >= 5)
            {
                spline.dict = new Dictionary <double, double>();

                BulirschStoerRationalInterpolation nevilleInterpol = new BulirschStoerRationalInterpolation(Commons.X, Commons.Y);
                for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
                {
                    spline.dict.Add(i, nevilleInterpol.Interpolate(i));
                }
            }

            /*
             * switch(spline.POWER)
             * {
             *  case 1:
             *      LinearSplineInterpolation splineInterpol = new LinearSplineInterpolation();
             *      splineInterpol.Init(Commons.xlist, Commons.ylist);
             *      for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i+=step)
             *      {
             *         // spline.listX.Add(i);
             *          spline.dict.Add(i, splineInterpol.Interpolate(i));
             *          //spline.listY.Add(splineInterpol.Interpolate(i));
             *      }
             *      break;
             *  case 2:
             *      //MessageBox.Show("do not work for now");
             *      QuadraticSpline quadraticSplineInterpol = new QuadraticSpline();
             *      quadraticSplineInterpol.Init(Commons.xlist, Commons.ylist);
             *      for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
             *      {
             *          //spline.listX.Add(i);
             *          //spline.listY.Add(quadraticSplineInterpol.Interpolate(i));
             *          spline.dict.Add(i, quadraticSplineInterpol.Interpolate(i));
             *      }
             *      break;
             *  case 3:
             *      CubicSplineInterpolation cubicSplineInterpol = new CubicSplineInterpolation();
             *      cubicSplineInterpol.Init(Commons.xlist, Commons.ylist);
             *      for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
             *      {
             *          //spline.listX.Add(i);
             *          //spline.listY.Add(cubicSplineInterpol.Interpolate(i));
             *          spline.dict.Add(i, cubicSplineInterpol.Interpolate(i));
             *      }
             *      break;
             *  default:
             *      CubicSplineInterpolation cubicSplineInterpol1 = new CubicSplineInterpolation();
             *      QuadraticSpline quadraticSplineInterpol1 = new QuadraticSpline();
             *      //MathNet.Numerics.Interpolation.NevillePolynomialInterpolation
             *      BulirschStoerRationalInterpolation nevilleInterpol = new BulirschStoerRationalInterpolation(Commons.X, Commons.Y);
             *      NevillePolynomialInterpolation logLinearInterpol = new NevillePolynomialInterpolation(Commons.X, Commons.Y);
             *      cubicSplineInterpol1.Init(Commons.xlist, Commons.ylist);
             *      quadraticSplineInterpol1.Init(Commons.xlist, Commons.ylist);
             *      for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step)
             *      {
             *          //spline.listX.Add(i);
             *          //spline.listY.Add(cubicSplineInterpol1.Interpolate(i));
             *         // if (Commons.xlist.Contains(i)&&spline.POWER%2!=0)
             *
             *          ///if (spline.POWER % 2 != 0)
             *          //    spline.dict.Add(i, cubicSplineInterpol1.Interpolate(i + spline.POWER * 1.5));
             *          //else spline.dict.Add(i, quadraticSplineInterpol1.Interpolate(i + spline.POWER * 1.5));
             *
             *          ///spline.dict.Add(i, nevilleInterpol.Interpolate(i));
             *          //spline.dict.Add(i, logLinearInterpol.Interpolate(i));
             *          //else if (Commons.xlist.Contains(i) && spline.POWER%2==0)
             *           //   spline.dict.Add(i, quadraticSplineInterpol1.Interpolate(i+spline.POWER*1.5));
             *      }
             *      break;
             * }*/
        }