예제 #1
0
        public void TestDeriveSineInv()
        {
            Expression <Func <double, double> > lambda = x => Math.Sin(1d / x);

            PartialDerivative pd         = new PartialDerivative();
            Expression        derivative = pd.Differentiate(lambda.Body, "x");

            Assert.AreEqual(ExpressionType.Multiply, derivative.NodeType);
            Assert.AreEqual("(-(1 / (x * x)) * Cosine((1 / x)))", derivative.ToString());
        }
예제 #2
0
        public void TestDeriveSine()
        {
            Expression <Func <double, double> > lambda = x => Math.Sin(x);

            PartialDerivative pd         = new PartialDerivative();
            Expression        derivative = pd.Differentiate(lambda.Body, "x");

            Assert.AreEqual(ExpressionType.Call, derivative.NodeType);
            Assert.AreEqual("Cosine(x)", derivative.ToString());
        }
예제 #3
0
        public void TestDeriveLinear()
        {
            Expression <Func <double, double> > lambda = x => 2 * x + 5;

            PartialDerivative pd         = new PartialDerivative();
            Expression        derivative = pd.Differentiate(lambda.Body, "x");

            Assert.AreEqual(ExpressionType.Constant, derivative.NodeType);
            Assert.AreEqual("2", derivative.ToString());
        }
예제 #4
0
        public void TestDeriveCosineProduct()
        {
            Expression <Func <double, double, double> > lambda = (x, y) => Math.Cos(x) * Math.Sin(y);

            PartialDerivative pd         = new PartialDerivative();
            Expression        derivative = pd.Differentiate(lambda.Body, "x");

            Assert.AreEqual(ExpressionType.Multiply, derivative.NodeType);
            Assert.AreEqual("(-Sine(x) * Sin(y))", derivative.ToString());

            /*
             * NOTE: The reason why the first is named "Sine" while the second uses "Sin" is
             * that Math.NET Palladium always uses the Math.NET Iridium trigonometric functions
             * (MathNet.Numerics.Trig.Sine(x)). However, the second instance (System.Math.Sin)
             * was not touched by Palladium at all and therefore is still using Math.Sin.
             */
        }