예제 #1
0
        /// <summary>
        /// Gives the value of the derivative using the quotient formula
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public double ProcessDerivative_Quotient(double input, BaseNode root)
        {
            BaseNode @base = root;
            double   x1    = input - h;
            double   x2    = input + h;
            double   y1    = @base.Calculate(x1);
            double   y2    = @base.Calculate(x2);

            return((y2 - y1) / (x2 - x1));
        }
예제 #2
0
        /// <summary>
        /// Creates a MacLaurien series based off the function
        /// </summary>
        /// <param name="mcLaurienRoot">Where the McLaurien Series will be outputted</param>
        /// <param name="order">Nth order of a series</param>
        public void CreateMcLaurienSeries(out BaseNode mcLaurienRoot, int order = 5)
        {
            if (derivativeRoot == null)
            {
                CreateDerivativeTree(); derivativeRoot.Simplify();
            }

            // we made sure that there is a derivative

            BaseNode myDerivative = Plotter.CloneTree(derivativeRoot);

            myDerivative.derivativeRoot = myDerivative;
            double[] values = new double[order + 1]; // values for functions (f(0), derivative of f(0), second derivative of f(0), etc..)

            values[0] = root.Calculate(0);           // set up a value for f(0)
            if (values.Length >= 2)
            {
                values[1] = derivativeRoot.Calculate(0);                      // set up a value of the first derivative of f(0)
            }
            if (values.Length >= 3)
            {
                for (int i = 2; i < values.Length; i++)
                {
                    myDerivative.CreateDerivativeTree(null);
                    values[i]    = myDerivative.derivativeRoot.Calculate(0);
                    myDerivative = myDerivative.derivativeRoot;
                }
            }

            List <BaseNode> mcLaurienItems = new List <BaseNode> ();

            SumNode result = new SumNode(null, null, null);

            result.left = new NumberNode(null, values[0]);

            for (int i = 1; i < values.Length; i++)
            {
                DivisionNode       item        = new DivisionNode(null, null, null);
                FactorialNode      denominator = new FactorialNode(new NumberNode(null, i), null); // not sure about this line
                MultiplicationNode numerator   = new MultiplicationNode(
                    new NumberNode(null, values[i]),
                    new PowerNode(new BasicFunctionXNode("", null), new NumberNode(null, i), null), null
                    );
                item.left  = numerator;
                item.right = denominator;
                mcLaurienItems.Add(item);
            }

            foreach (var item in mcLaurienItems)
            {
                result.PutToRightNode(item);
            }

            mcLaurienRoot = result;
        }
예제 #3
0
        /// <summary>
        /// Returns the y-value for x-value based on a previously built binary tree. To be called only after ProcessString() func
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public double ProcessTree(double input, BaseNode root)
        {
            BaseNode @base = root;

            return(@base.Calculate(input));
        }