示例#1
0
        public void DerivativeTest2()
        {
            IExpression exp = new Add(new Mul(new Number(2), new Variable("x")), new Mul(new Number(3), new Variable("x")));
            IExpression deriv = exp.Differentiate();

            Assert.AreEqual("(2 * 1) + (3 * 1)", deriv.ToString());
        }
示例#2
0
        public void DerivativeTest3()
        {
            // 2x + 3
            Number num1 = new Number(2);
            Variable x = new Variable("x");
            Mul mul1 = new Mul(num1, x);

            Number num2 = new Number(3);

            IExpression exp = new Add(mul1, num2);
            IExpression deriv = exp.Differentiate();

            Assert.AreEqual("2 * 1", deriv.ToString());

            num1.Value = 5;
            Assert.AreEqual("(5 * x) + 3", exp.ToString());
            Assert.AreEqual("2 * 1", deriv.ToString());
        }
示例#3
0
 public void PartialDerivativeTest3()
 {
     IExpression exp = new Add(new Variable("x"), new Number(1));
     IExpression deriv = exp.Differentiate(new Variable("y"));
     Assert.AreEqual("0", deriv.ToString());
 }
示例#4
0
 public void PartialDerivativeTest2()
 {
     IExpression exp = new Add(new Add(new Mul(new Variable("x"), new Variable("y")), new Variable("x")), new Variable("y"));
     IExpression deriv = exp.Differentiate(new Variable("y"));
     Assert.AreEqual("(x * 1) + 1", deriv.ToString());
 }