Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the McLaurien series based off already given values for derivatives
        /// </summary>
        /// <param name="mcLaurienRoot">Where the McLaurien series will be outputted</param>
        /// <param name="order">Order of the McLaurien</param>
        public void CreateMcLaurienSeriesByLimits(out BaseNode mcLaurienRoot, int order)
        {
            List <double> values = new List <double> ();

            for (int i = 0; i <= order; i++)
            {
                var value = ProcessNthDerivative_Quotient(0, i, root);
                values.Add(value);
            }

            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.Count; 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;
        }
Exemplo n.º 3
0
        public BaseNode CreatePolynomialThroughPoints(DataPoint[] points)
        {
            /* Let X be the number of points user has selected
             * Then the polynomial is going to be of the degree (X - 1)
             *
             * Example: X = 5 => ax^4 + bx^3 + cx^2 + dx + e
             */

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

            var firstDivision       = ProduceLagrange(points, 0);
            var firstMultiplication = new MultiplicationNode(firstDivision, new NumberNode(null, points[0].Y), null);

            polynomial.left = firstMultiplication;

            for (int j = 1; j < points.Length; j++)
            {
                var division            = ProduceLagrange(points, j);
                MultiplicationNode node = new MultiplicationNode(division, new NumberNode(null, points[j].Y), null);
                polynomial.PutToRightNode(node);
            }

            return(polynomial);
        }