Exemplo n.º 1
0
        public void Derive_ComplexConstant_Returns0()
        {
            Environment environment = new Environment();
            SyntaxNode  node        = Parser.ParseExpression("(2 * 2) + 4 ^ 2 - 5 / 5", environment);
            Expression  expression  = new Expression(node, environment);
            Derivative  derivative  = new Derivative(expression, "x");

            Assert.AreEqual(derivative.Derive().ToString(), "0");
        }
Exemplo n.º 2
0
        public void Derive_x_Returns1()
        {
            Environment environment = new Environment();

            environment.AddSymbol("x");
            SyntaxNode node       = Parser.ParseExpression("x", environment);
            Expression expression = new Expression(node, environment);
            Derivative derivative = new Derivative(expression, "x");

            Assert.AreEqual(derivative.Derive().ToString(), "1");
        }
Exemplo n.º 3
0
 public static void Main(string[] args)
 {
     while (true)
     {
         Console.WriteLine("Enter an expression to derive");
         string rawExpression = Console.ReadLine();
         ExpressionParser.Parsing.Environment environment = new ExpressionParser.Parsing.Environment();
         environment.AddSymbol("x");
         SyntaxNode node       = Parser.ParseExpression(rawExpression, environment);
         Expression expression = new Expression(node, environment);
         Derivative derivative = new Derivative(expression, "x");
         Console.WriteLine(derivative.Derive());
         Console.WriteLine();
     }
 }
Exemplo n.º 4
0
        private void CalculateOptimizeProductionAmount()
        {
            Func <double, double> f = x => A + B * x + C * Math.Pow(x, 2);

            Func <double, double> dtk = x => A / x + B + C * x;

            var dtkFirstDerivative = Derivative.Derive(dtk, 1);

            OptimizeAmount          = Math.Round(FindRoots.OfFunction(dtkFirstDerivative, 1, 500));
            OptimizeProductionCosts = dtk(OptimizeAmount);

            if (OptimizeProductionCosts < SellPrice)
            {
                Func <double, double> g = x => SellPrice * x - (A + B * x + C * Math.Pow(x, 2));
                var gFirstDerivative    = Derivative.Derive(g, 1);
                ProfitAmount = Math.Round(FindRoots.OfFunction(gFirstDerivative, 1, 500));
                Profit       = g(ProfitAmount);
            }
            else
            {
                Profit = double.NaN;
            }
        }