public override MathFunction Derivative(int order)
        {
            MathFunction f = functions[0],
                         g = functions[1];

            return(this * (f.Derivative(1) * g / f + new LnFunction(1.0d, f) * g.Derivative(1)));
        }
예제 #2
0
        public override MathFunction Derivative(int order)
        {
            MathFunction f = functions[0],
                         g = functions[1];

            return(new PowerFunction(1.0, f, g) * new LnFunction(1.0, f) * g.Derivative(1));
        }
        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);
        }