Example #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());
        }
Example #2
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());
        }
Example #3
0
        static void Main()
        {
            //Type the function you want to simplify
            Expression <Func <double, double, double, double, double> > function =
                (x, y, z, u) => (x + 42) / 1 + y * 0 / (z - 0) + 43 - Math.Pow(x, 0) * Math.Pow(u, 1) / (0 + 5);

            var tree           = Expressions2Tree.Parse(function);
            var simplifiedTree = ComputerAlgebra.Simplify(tree);

            Console.WriteLine("Initial function:{1}F(x,y,z,u) = {0}{1}", tree, Environment.NewLine);
            Console.WriteLine("Result of simplification:{1}{0}", simplifiedTree, Environment.NewLine);
        }
Example #4
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());
        }
Example #5
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);
        }
Example #6
0
        /// <summary>
        /// Calculate partial differentiation of function, represented as expression
        /// </summary>
        /// <seealso cref="Differentiate(INode,int,string)"/>
        /// <param name="e"></param>
        /// <param name="index"></param>
        /// <param name="variable"></param>
        /// <returns></returns>
        public static Expression Differentiate(Expression e, int index = 0, String variable = "")
        {
            var node = Expressions2Tree.Parse(e);

            return(Tree2Expression.Parse(Differentiate(node, index, variable)));
        }
Example #7
0
 /// <summary>
 /// Simplify expression, using simplification rules from <see cref="RulesLibrary"/>
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 public static Expression Simplify(Expression e)
 {
     return(Tree2Expression.Parse(Simplify(Expressions2Tree.Parse(e))));
 }
Example #8
0
 public static INode SimplifyBinaryExpression(Expression e)
 {
     return(ComputerAlgebra.Simplify(Expressions2Tree.Parse(e)));
 }