Ejemplo n.º 1
0
 protected override Number Evaluate(Number number)
 {
     return(NumberMath.Ln(number));
 }
Ejemplo n.º 2
0
        public override IExpression?Differentiate(string byVariable)
        {
            if (Right is ConstantExpression)
            {
                // f(x) = g(x)^n
                // f'(x) = n * g'(x) * g(x)^(n-1)
                return
                    (new MultiplyExpression(new MultiplyExpression(Right, Left?.Differentiate(byVariable)),
                                            new ExponentExpression(Left, new SubtractExpression(Right, new ConstantExpression(1)))));
            }
            var simple = Left?.Simplify();

            if (simple is ConstantExpression constant)
            {
                // f(x) = a^g(x)
                // f'(x) = (ln a) * g'(x) * a^g(x)
                var a = constant.Value;
                return(new MultiplyExpression(new MultiplyExpression(new ConstantExpression(NumberMath.Ln(a)), Right?.Differentiate(byVariable)), new ExponentExpression(simple, Right)));
            }
            throw new CannotDifferentiateException(Resources.CanotDifferentiate);
        }