protected PiecewiseIntervalPolynomialCurveElement GenerateCurve(CubicSplineInterpolationCurveParam curveParam)
 {
     double[,] coefficientsArray = new double[curveParam.Count, curveParam.Count];
     double[,] constantArray = new double[curveParam.Count, 1];
     double uVal, dVal, val1, val2;
     for (int i = 1; i < curveParam.Count - 1; i++)
     {
         uVal = (curveParam[i].X.AccurateValue - curveParam[i - 1].X.AccurateValue) / (curveParam[i + 1].X.AccurateValue - curveParam[i - 1].X.AccurateValue);
         dVal = 6 / (curveParam[i + 1].X.AccurateValue - curveParam[i - 1].X.AccurateValue) * (
             (curveParam[i + 1].Y.AccurateValue - curveParam[i].Y.AccurateValue) / (curveParam[i + 1].X.AccurateValue - curveParam[i].X.AccurateValue) - 
             (curveParam[i].Y.AccurateValue - curveParam[i - 1].Y.AccurateValue) / (curveParam[i].X.AccurateValue - curveParam[i - 1].X.AccurateValue)
             );
         coefficientsArray[i, i - 1] = uVal;
         coefficientsArray[i, i] = 2;
         coefficientsArray[i, i + 1] = 1 - uVal;
         constantArray[i, 0] = dVal;
     }
     switch (curveParam.BorderConditionType)
     {
         case CSIBorderConditionType.First_Order_Derivative:
             val1 = 6 / (curveParam[2].X.AccurateValue - curveParam[1].X.AccurateValue) * (
                 (curveParam[1].Y.AccurateValue - curveParam[0].Y.AccurateValue) / (curveParam[1].X.AccurateValue - curveParam[0].X.AccurateValue) -
                 curveParam.LeftBorderValue.AccurateValue
                 );
             val2 = 6 / (curveParam[curveParam.Count - 1].X.AccurateValue - curveParam[curveParam.Count - 2].X.AccurateValue) * (
                 curveParam.RightBorderValue.AccurateValue -
                 (curveParam[curveParam.Count - 1].Y.AccurateValue - curveParam[curveParam.Count - 2].Y.AccurateValue) / (curveParam[curveParam.Count - 1].X.AccurateValue - curveParam[curveParam.Count - 2].X.AccurateValue)
                 );
             coefficientsArray[0, 0] = 2;
             coefficientsArray[0, 1] = 1;
             coefficientsArray[curveParam.Count - 1, curveParam.Count - 2] = 1;
             coefficientsArray[curveParam.Count - 1, curveParam.Count - 1] = 2;
             constantArray[0, 0] = val1;
             constantArray[curveParam.Count - 1, 0] = val2;
             break;
         case CSIBorderConditionType.Second_Order_Derivative:
             coefficientsArray[0, 0] = 1;
             coefficientsArray[curveParam.Count - 1, curveParam.Count - 1] = 1;
             constantArray[0, 0] = curveParam.LeftBorderValue.AccurateValue;
             constantArray[curveParam.Count - 1, 0] = curveParam.RightBorderValue.AccurateValue;
             break;
         case CSIBorderConditionType.Cyclicity:
             val1 = curveParam[1].X.AccurateValue - curveParam[0].X.AccurateValue;
             coefficientsArray[0, 0] = val1;
             coefficientsArray[0, 1] = 2 * val1;
             val1 = curveParam[curveParam.Count - 1].X.AccurateValue - curveParam[curveParam.Count - 2].X.AccurateValue;
             coefficientsArray[0, curveParam.Count - 2] = val1;
             coefficientsArray[0, curveParam.Count - 1] = 2 * val1;
             coefficientsArray[curveParam.Count - 1, 0] = 1;
             coefficientsArray[curveParam.Count - 1, curveParam.Count - 1] = -1;
             val2 = 6 * (
                 (curveParam[1].Y.AccurateValue - curveParam[0].Y.AccurateValue) / (curveParam[1].X.AccurateValue - curveParam[0].X.AccurateValue) - 
                 (curveParam[curveParam.Count - 1].Y.AccurateValue - curveParam[curveParam.Count - 2].Y.AccurateValue) / (curveParam[curveParam.Count - 1].X.AccurateValue - curveParam[curveParam.Count - 2].X.AccurateValue)
                 );
             constantArray[0, 0] = val2;
             break;
     }
     LinearEquationSet equations = new LinearEquationSet(new Matrix(coefficientsArray), new Matrix(constantArray));
     Matrix result = equations.AnswerMatrix;
     List<NormalIntervalPolynomialCurveElement> curves = new List<NormalIntervalPolynomialCurveElement>();
     List<DoubleExtension> cutPoints = new List<DoubleExtension>();
     cutPoints.Add(curveParam[0].X);
     for (int i = 1; i < curveParam.Count; i++)
     {
         curves.Add(new NormalIntervalPolynomialCurveElement(result[i - 1, 0], result[i, 0], curveParam[i - 1], curveParam[i]));
         cutPoints.Add(curveParam[i].X);
     }
     return new PiecewiseIntervalPolynomialCurveElement(curves, cutPoints);
 }
        private NormalIntervalPolynomialCurveElement GenerateCurve(PolynomialCurveParam curveParam)
        {
            Debug.Assert(curveParam.PolynomialCurveType == PolynomialCurveType.Lagrange, @"This interpolated method """"GenerateCurve"""" only supports Lagarange Polynomial Curve.");
            double[,] coefficientsArray = new double[count, count];
            double[,] constantArray = new double[count, 1];
            double coef, x;
            
            for (int i = 0; i < count; i++)
            {
                constantArray[i, 0] = curveParam[i].Y.AccurateValue;
                coef = 1;
                x = curveParam[i].X.AccurateValue;
                for (int j = 0; j < count; j++)
                {
                    coefficientsArray[i, j] = coef;
                    coef *= x;
                }
            }

            LinearEquationSet equations = new LinearEquationSet(new Matrix(coefficientsArray), new Matrix(constantArray));
            Matrix result = equations.AnswerMatrix;

            List<DoubleExtension> coefs = new List<DoubleExtension>();
            for (int i = 0; i < count; i++)
            {
                coefs.Add(new DoubleExtension(result[i, 0]));
            }
            return new NormalIntervalPolynomialCurveElement(coefs, count, new DataInterval(curveParam.PointList.LeftBorderPoint.X, curveParam.PointList.RightBorderPoint.X)); 
            //OrderedCurvePointList pointList = param.PointList;
            //List<NormalIntervalPolynomialCurveElement> polynomialCurve = new List<NormalIntervalPolynomialCurveElement>();
            //List<DoubleExtension> coefficients = null;
            //List<DoubleExtension> cutPoints = new List<DoubleExtension>();
            //cutPoints.Add(pointList[0].X);
            //for (int i = 2; i < pointList.Count; i = i + 2)
            //{
            //    coefficients = MathExtension.CalculateQuadraticPolynomialCoefficients(pointList[i - 2], pointList[i - 1], pointList[i]);
            //    polynomialCurve.Add(new NormalIntervalPolynomialCurveElement(coefficients, 3, pointList[i - 2].X, pointList[i].X));
            //    cutPoints.Add(pointList[i].X);
            //}
            //return new PiecewiseIntervalPolynomialCurveElement(polynomialCurve, cutPoints);
        }