Exemplo n.º 1
0
        public void DerivativeTest3()
        {
            // x ^ 3
            Variable x = new Variable("x");
            Number num1 = new Number(3);

            IExpression exp = new Pow(x, num1);
            IExpression deriv = exp.Differentiate();

            Assert.AreEqual("1 * (3 * (x ^ (3 - 1)))", deriv.ToString());

            num1.Value = 4;
            Assert.AreEqual("x ^ 4", exp.ToString());
            Assert.AreEqual("1 * (3 * (x ^ (3 - 1)))", deriv.ToString());

            // 2 ^ (3x)
            Number num2 = new Number(2);
            num1 = new Number(3);
            Mul mul = new Mul(num1, x.Clone());

            exp = new Pow(num2, mul);
            deriv = exp.Differentiate();

            Assert.AreEqual("(ln(2) * (2 ^ (3 * x))) * (3 * 1)", deriv.ToString());

            num1.Value = 4;
            Assert.AreEqual("2 ^ (4 * x)", exp.ToString());
            Assert.AreEqual("(ln(2) * (2 ^ (3 * x))) * (3 * 1)", deriv.ToString());
        }
Exemplo n.º 2
0
        public void PowDerivativeTest3()
        {
            // x ^ 3
            var x = new Variable("x");
            var num1 = new Number(3);

            var exp = new Pow(x, num1);
            var deriv = Differentiate(exp);

            Assert.Equal("1 * 3 * (x ^ (3 - 1))", deriv.ToString());

            num1.Value = 4;
            Assert.Equal("x ^ 4", exp.ToString());
            Assert.Equal("1 * 3 * (x ^ (3 - 1))", deriv.ToString());

            // 2 ^ (3x)
            var num2 = new Number(2);
            num1 = new Number(3);
            var mul = new Mul(num1, x.Clone());

            exp = new Pow(num2, mul);
            deriv = Differentiate(exp);

            Assert.Equal("ln(2) * (2 ^ (3 * x)) * 3 * 1", deriv.ToString());

            num1.Value = 4;
            Assert.Equal("2 ^ (4 * x)", exp.ToString());
            Assert.Equal("ln(2) * (2 ^ (3 * x)) * 3 * 1", deriv.ToString());
        }