Пример #1
0
        public void DiffPowConstant()
        {
            Expression <Del1> expression = (x) => Math.Pow(x, 3);

            Assert.AreEqual(
                new ScalarProduct <double>(new Constant <double>(3.0), new Pow <double>(VariableNode.Make <double>(0, "x"), new Constant <double>(2.0))).ToString(),
                ComputerAlgebra.Differentiate(Expressions2Tree.Parse(expression.Body), variable: "x").ToString());
        }
Пример #2
0
        public void DiffProduct()
        {
            Expression <Del2> expression = (x, y) => x * y;

            Assert.AreEqual(
                "y",
                ComputerAlgebra.Differentiate(expression.Body, variable: "x").ToString());
        }
Пример #3
0
        public void DiffNegate()
        {
            Expression <Del1> expression = (x) => - x;

            Assert.AreEqual(
                "-1",
                ComputerAlgebra.Differentiate(expression.Body, variable: "x").ToString());
        }
Пример #4
0
        public void DiffDivide()
        {
            Expression <Del2> expression = (x, y) => x / y;

            Assert.AreEqual(
                new Divide <double>(
                    VariableNode.Make <double>(1, "y"),
                    new Pow <double>(VariableNode.Make <double>(1, "y"), new Constant <double>(2))).ToString(),
                ComputerAlgebra.Differentiate(Expressions2Tree.Parse(expression.Body), variable: "x").ToString());
        }
Пример #5
0
        public void DiffPowY()
        {
            Expression <Del2> expression = (x, y) => Math.Pow(x, y);

            Assert.AreEqual(
                new ScalarProduct <double>(
                    new Pow <double>(
                        VariableNode.Make <double>(0, "x"),
                        VariableNode.Make <double>(1, "y")),
                    new Ln(VariableNode.Make <double>(0, "x")))
                .ToString(),
                ComputerAlgebra.Differentiate(Expressions2Tree.Parse(expression.Body), variable: "y").ToString());
        }
Пример #6
0
        static void Main()
        {
            //Type the function you want to differentiate
            Expression <Func <double, double, double, double> > function = (x, y, z) => Math.Pow(x, 3) * y - Math.Pow(x, y) + 5 * z;
            var node = Expressions2Tree.Parse(function);

            // Differentiation
            var resultFromDiffX = ComputerAlgebra.Differentiate(node, variable: "x");
            var resultFromDiffY = ComputerAlgebra.Differentiate(node, variable: "y");
            var resultFromDiffZ = ComputerAlgebra.Differentiate(node, variable: "z");

            // Output
            Console.WriteLine("Initial function:{1}F(x,y,z) = {0}{1}", node, Environment.NewLine);
            Console.WriteLine("dF/dx = {0}{1}", resultFromDiffX, Environment.NewLine);
            Console.WriteLine("dF/dy = {0}{1}", resultFromDiffY, Environment.NewLine);
            Console.WriteLine("dF/dz = {0}{1}", resultFromDiffZ, Environment.NewLine);
        }