private double CalculateQuadratureCoef(int index, double[] solutions, int n)
        {
            double Ai = 0;

            MathFunction func = new ConstFunction(1.0d);

            for (int i = 0; i <= n; i++)
            {
                if (i != index)
                {
                    func *= (new XFunction(1.0d) - solutions[i]) / (solutions[index] - solutions[i]);
                }
            }

            Ai = func.CalculateDeterminedIntegral(new SimpsonMethod(), -1, 1, powerForIntegralCalculation);

            return(Ai);
        }
        public virtual MathFunction Derivative(int order)
        {
            if (functions.Count == 0)
            {
                throw new Exception("Function is empty!");
            }

            if (order < 0)
            {
                throw new Exception("Incorrect derivative order!");
            }

            if (order == 0)
            {
                return(new MathFunction(coef, type, functions.ToArray()));
            }

            MathFunction result = 0.0d;

            switch (type)
            {
            case MathFunctionType.Sum:
                result = functions[0].Derivative(order);

                for (int i = 1; i < functions.Count; i++)
                {
                    result += functions[i].Derivative(order);
                }

                break;

            case MathFunctionType.Multiplication:
                result = new ConstFunction(0.0d);

                for (int i = 0; i < functions.Count; i++)
                {
                    MathFunction func = functions[i].Derivative(1);
                    for (int j = 0; j < functions.Count; j++)
                    {
                        if (i != j)
                        {
                            func *= functions[j];
                        }
                    }

                    result += func;
                }

                result = Derivative(order - 1);

                break;

            case MathFunctionType.Division:
                MathFunction f = functions[0],
                             g = functions[1];

                result = (f.Derivative(1) * g - g.Derivative(1) * f) / (g ^ 2);

                result = Derivative(order - 1);
                break;
            }

            return(result);
        }