Ejemplo 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());
        }
Ejemplo n.º 2
0
        public void AddDiffNum_VarSubNum_()
        {
            // 2 + (x - 2)
            var add = new Add(new Number(2), new Sub(new Variable("x"), new Number(2)));
            var expected = new Variable("x");

            SimpleTest(add, expected);
        }
Ejemplo n.º 3
0
        public DefiniteIntegral(
			IExpression expression, 
			Variable variable, 
			IExpression left, 
			IExpression right)
            : base(new[] { expression, variable, left, right }, 4)
        {
        }
Ejemplo n.º 4
0
        public void AbsDerivativeTest2()
        {
            var num = new Number(2);
            var x = new Variable("x");
            var mul = new Mul(num, x);

            var exp = new Abs(mul);
            var deriv = Differentiate(exp);

            Assert.Equal("2 * 1 * ((2 * x) / abs(2 * x))", deriv.ToString());

            num.Value = 3;
            Assert.Equal("abs(3 * x)", exp.ToString());
            Assert.Equal("2 * 1 * ((2 * x) / abs(2 * x))", deriv.ToString());
        }
Ejemplo n.º 5
0
        public void DerivativeTest2()
        {
            // log(x, 2)
            Number num = new Number(2);
            Variable x = new Variable("x");

            IExpression exp = new Log(x, num);
            IExpression deriv = exp.Differentiate();

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

            num.Value = 4;
            Assert.AreEqual("log(4, x)", exp.ToString());
            Assert.AreEqual("1 / (x * ln(2))", deriv.ToString());
        }
Ejemplo n.º 6
0
        public void AbsDerivativeTest2()
        {
            Number num = new Number(2);
            Variable x = new Variable("x");
            Mul mul = new Mul(num, x);

            IExpression exp = new Abs(mul);
            IExpression deriv = Differentiate(exp);

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

            num.Value = 3;
            Assert.AreEqual("abs(3 * x)", exp.ToString());
            Assert.AreEqual("(2 * 1) * ((2 * x) / abs(2 * x))", deriv.ToString());
        }
Ejemplo n.º 7
0
        public void DerivativeTest3()
        {
            Number num = new Number(2);
            Variable x = new Variable("x");
            Mul mul = new Mul(num, x);

            IExpression exp = new Tan(mul);
            IExpression deriv = exp.Differentiate();

            Assert.AreEqual("(2 * 1) / (cos(2 * x) ^ 2)", deriv.ToString());

            num.Value = 5;
            Assert.AreEqual("tan(5 * x)", exp.ToString());
            Assert.AreEqual("(2 * 1) / (cos(2 * x) ^ 2)", deriv.ToString());
        }
Ejemplo n.º 8
0
        public void DerivativeTest2()
        {
            // lg(2x)
            Number num = new Number(2);
            Variable x = new Variable("x");
            Mul mul = new Mul(num, x);

            IExpression exp = new Lg(mul);
            IExpression deriv = exp.Differentiate();

            Assert.AreEqual("(2 * 1) / ((2 * x) * ln(10))", deriv.ToString());

            num.Value = 3;
            Assert.AreEqual("lg(3 * x)", exp.ToString());
            Assert.AreEqual("(2 * 1) / ((2 * x) * ln(10))", deriv.ToString());
        }
Ejemplo n.º 9
0
        public void DerivativeTest3()
        {
            // cot(2x)
            Number num = new Number(2);
            Variable x = new Variable("x");
            Mul mul = new Mul(num, x);

            IExpression exp = new Cot(mul);
            IExpression deriv = exp.Differentiate();

            Assert.AreEqual("-((2 * 1) / (sin(2 * x) ^ 2))", deriv.ToString());

            num.Value = 3;
            Assert.AreEqual("cot(3 * x)", exp.ToString());
            Assert.AreEqual("-((2 * 1) / (sin(2 * x) ^ 2))", deriv.ToString());
        }
Ejemplo n.º 10
0
        public void DerivativeTest2()
        {
            // arcsec(2x)
            Number num = new Number(2);
            Variable x = new Variable("x");
            Mul mul = new Mul(num, x);

            IExpression exp = new Arcsec(mul);
            IExpression deriv = exp.Differentiate();

            Assert.AreEqual("(2 * 1) / (abs(2 * x) * sqrt(((2 * x) ^ 2) - 1))", deriv.ToString());

            num.Value = 4;
            Assert.AreEqual("arcsec(4 * x)", exp.ToString());
            Assert.AreEqual("(2 * 1) / (abs(2 * x) * sqrt(((2 * x) ^ 2) - 1))", deriv.ToString());
        }
Ejemplo n.º 11
0
        public void DerivativeTest3()
        {
            // exp(2x)
            Number num = new Number(2);
            Variable x = new Variable("x");
            Mul mul = new Mul(num, x);

            IExpression exp = new Exp(mul);
            IExpression deriv = exp.Differentiate();

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

            num.Value = 6;
            Assert.AreEqual("exp(6 * x)", exp.ToString());
            Assert.AreEqual("(2 * 1) * exp(2 * x)", deriv.ToString());
        }
Ejemplo n.º 12
0
        public void DerivativeTest3()
        {
            // arccos(2x)
            Number num = new Number(2);
            Variable x = new Variable("x");
            Mul mul = new Mul(num, x);

            IExpression exp = new Arccos(mul);
            IExpression deriv = exp.Differentiate();

            Assert.AreEqual("-((2 * 1) / sqrt(1 - ((2 * x) ^ 2)))", deriv.ToString());

            num.Value = 6;
            Assert.AreEqual("arccos(6 * x)", exp.ToString());
            Assert.AreEqual("-((2 * 1) / sqrt(1 - ((2 * x) ^ 2)))", deriv.ToString());
        }
Ejemplo n.º 13
0
        public void DerivativeTest2()
        {
            Number num1 = new Number(2);
            Variable x = new Variable("x");
            Mul mul1 = new Mul(num1, x);

            Number num2 = new Number(3);
            Mul mul2 = new Mul(num2, x.Clone());

            IExpression exp = new Sub(mul1, mul2);
            IExpression deriv = exp.Differentiate();

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

            num1.Value = 5;
            num2.Value = 4;
            Assert.AreEqual("(5 * x) - (4 * x)", exp.ToString());
            Assert.AreEqual("(2 * 1) - (3 * 1)", deriv.ToString());
        }
Ejemplo n.º 14
0
        public void DerivativeTest3()
        {
            // (2x) / (3x)
            Number num1 = new Number(2);
            Variable x = new Variable("x");
            Mul mul1 = new Mul(num1, x);

            Number num2 = new Number(3);
            Mul mul2 = new Mul(num2, x.Clone());

            IExpression exp = new Div(mul1, mul2);
            IExpression deriv = exp.Differentiate();

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

            num1.Value = 4;
            num2.Value = 5;
            Assert.AreEqual("(4 * x) / (5 * x)", exp.ToString());
            Assert.AreEqual("(((2 * 1) * (3 * x)) - ((2 * x) * (3 * 1))) / ((3 * x) ^ 2)", deriv.ToString());
        }
Ejemplo n.º 15
0
        public void MulSecondOne()
        {
            var mul = new Mul(new Variable("x"), new Number(1));
            var expected = new Variable("x");

            SimpleTest(mul, expected);
        }
Ejemplo n.º 16
0
        public void PowerOne()
        {
            var pow = new Pow(new Variable("x"), new Number(1));
            var expected = new Variable("x");

            SimpleTest(pow, expected);
        }
Ejemplo n.º 17
0
        public void MulSameVar8()
        {
            // 2x * 3x
            var var = new Variable("x");
            var mul = new Mul(new Mul(new Number(2), var), new Mul(new Number(3), var));
            var expected = new Mul(new Number(6), new Pow(var, new Number(2)));

            SimpleTest(mul, expected);
        }
Ejemplo n.º 18
0
        public void MulSameVar9()
        {
            // (x * 2) * (x * 3)
            var var = new Variable("x");
            var mul = new Mul(new Mul(var, new Number(2)), new Mul(var, new Number(3)));
            var expected = new Mul(new Number(6), new Pow(var, new Number(2)));

            SimpleTest(mul, expected);
        }
Ejemplo n.º 19
0
        public void RootOne()
        {
            var root = new Root(new Variable("x"), new Number(1));
            var expected = new Variable("x");

            SimpleTest(root, expected);
        }
Ejemplo n.º 20
0
        public void MulSameVar11()
        {
            // 2x * -3x
            var var = new Variable("x");
            var mul = new Mul(new Mul(new Number(2), var), new Mul(new Number(-0.5), var));
            var expected = new UnaryMinus(new Pow(var, new Number(2)));

            SimpleTest(mul, expected);
        }
Ejemplo n.º 21
0
        public void MulSameVar1()
        {
            // x * x
            var var = new Variable("x");
            var mul = new Mul(var, var);
            var expected = new Pow(var, new Number(2));

            SimpleTest(mul, expected);
        }
Ejemplo n.º 22
0
        public void MulNegativeRightParamTest1()
        {
            // sin(cos(x))
            var x = new Variable("x");
            var mul = new Mul(new Cos(new Cos(x)), new UnaryMinus(new Sin(x)));
            var expected = new UnaryMinus(new Mul(new Sin(x), new Cos(new Cos(x))));

            SimpleTest(mul, expected);
        }
Ejemplo n.º 23
0
        public void MulDiff_VarDivNum_MulNum()
        {
            // (x / 2) * 2
            var mul = new Mul(new Div(new Variable("x"), new Number(2)), new Number(2));
            var expected = new Variable("x");

            SimpleTest(mul, expected);
        }
Ejemplo n.º 24
0
        public void SinhArsinh()
        {
            var exp = new Sinh(new Arsinh(new Variable("x")));
            var expected = new Variable("x");

            SimpleTest(exp, expected);
        }
Ejemplo n.º 25
0
        public void DoubleUnary()
        {
            var un = new UnaryMinus(new UnaryMinus(new Variable("x")));
            var expected = new Variable("x");

            SimpleTest(un, expected);
        }
Ejemplo n.º 26
0
        public void SecArcsec()
        {
            var exp = new Sec(new Arcsec(new Variable("x")));
            var expected = new Variable("x");

            SimpleTest(exp, expected);
        }
Ejemplo n.º 27
0
        public void DivSameVars()
        {
            var x = new Variable("x");
            var div = new Div(x, x);
            var expected = new Number(1);

            SimpleTest(div, expected);
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Derivative"/> class.
 /// </summary>
 /// <param name="expression">The expression.</param>
 /// <param name="variable">The variable.</param>
 public Derivative(IExpression expression, Variable variable)
     : base(new[] { expression, variable }, 2)
 {
 }
Ejemplo n.º 29
0
        public void MulDiffNumMul_VarDivNum_()
        {
            // 2 * (x / 2)
            var mul = new Mul(new Number(2), new Div(new Variable("x"), new Number(2)));
            var expected = new Variable("x");

            SimpleTest(mul, expected);
        }
Ejemplo n.º 30
-1
        public void DerivativeTest2()
        {
            // 2x
            Number num = new Number(2);
            Variable x = new Variable("x");

            IExpression exp = new Mul(num, x);
            IExpression deriv = exp.Differentiate();

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

            num.Value = 3;
            Assert.AreEqual("3 * x", exp.ToString());
            Assert.AreEqual("2 * 1", deriv.ToString());
        }