示例#1
0
        private Node getMaclaurinSerieRecursiveAccurate(int counter, int order, Node curNode)
        {
            Node   nodeTim   = new NodeTimes();
            Node   nodeDiv   = new NodeDivision();
            Node   nodeFac   = new NodeFactorial();
            Node   nodePow   = new NodePower();
            double zeroValue = curNode.GetValueForX(0);

            nodeTim.AddNode1(nodeDiv);
            nodeTim.AddNode2(nodePow);
            nodeDiv.AddNode1(new NodeNumber(false, false, zeroValue));
            nodeDiv.AddNode2(nodeFac);
            nodeFac.AddNode1(new NodeNumber(false, false, counter - 1));
            nodePow.AddNode1(new NodeNumber(true, false, 1));
            nodePow.AddNode2(new NodeNumber(false, false, counter - 1));

            if (counter == order)
            {
                return(nodeTim);
            }
            else if (counter < order && counter > 0)
            {
                Node nodePlus = new NodePlus();
                nodePlus.AddNode1(nodeTim);
                curNode = curNode.GetDerivative();
                Node receivedReplacementNode;
                curNode = curNode.MakeNodeClean(null, out receivedReplacementNode);
                nodePlus.AddNode2(getMaclaurinSerieRecursiveAccurate(counter + 1, order, curNode));
                return(nodePlus);
            }
            else
            {
                throw new Exception("Error while making Maclaurin serie: counter problem: " + counter);
            }
        }
        public override Node Clone()
        {
            Node newNode  = new NodeFactorial();
            Node newNode1 = node1.Clone();

            newNode.AddNode1(newNode1);
            return(newNode);
        }
示例#3
0
        private Node drawMaclaurinSerieFastRecursive(int counter, int order, double[] maclaurinValues, GraphDrawer drawer, Node prevCompletedNode)
        {
            NodeHolder nh;
            Node       nodeTim   = new NodeTimes();
            Node       nodeDiv   = new NodeDivision();
            Node       nodeFac   = new NodeFactorial();
            Node       nodePow   = new NodePower();
            double     zeroValue = maclaurinValues[counter - 1];

            nodeTim.AddNode1(nodeDiv);
            nodeTim.AddNode2(nodePow);
            nodeDiv.AddNode1(new NodeNumber(false, false, zeroValue));
            nodeDiv.AddNode2(nodeFac);
            nodeFac.AddNode1(new NodeNumber(false, false, counter - 1));
            nodePow.AddNode1(new NodeNumber(true, false, 1)); //X
            nodePow.AddNode2(new NodeNumber(false, false, counter - 1));

            if (counter == order)
            {
                Node nodePlus = new NodePlus();
                if (prevCompletedNode != null)
                {
                    nodePlus.AddNode1(nodeTim);
                    nodePlus.AddNode2(prevCompletedNode);
                    prevCompletedNode = nodePlus.Clone();
                    nh = new NodeHolder(prevCompletedNode);
                }
                else
                {
                    prevCompletedNode = nodeTim;
                    nh = new NodeHolder(prevCompletedNode);
                }
                if (counter == 1)
                {
                    drawer.drawFunction(nh, true);
                }
                else
                {
                    drawer.drawFunction(nh, false);
                }
                return(nodeTim);
            }
            else if (counter < order && counter > 0)
            {
                Node nodePlus = new NodePlus();
                if (prevCompletedNode != null)
                {
                    nodePlus.AddNode1(nodeTim);
                    nodePlus.AddNode2(prevCompletedNode);
                    prevCompletedNode = nodePlus.Clone();
                    nh = new NodeHolder(prevCompletedNode);
                }
                else
                {
                    prevCompletedNode = nodeTim;
                    nh = new NodeHolder(prevCompletedNode);
                }
                if (counter == 1)
                {
                    drawer.drawFunction(nh, true);
                }
                else
                {
                    drawer.drawFunction(nh, false);
                }
                nodePlus.AddNode1(nodeTim);
                nodePlus.AddNode2(drawMaclaurinSerieFastRecursive(counter + 1, order, maclaurinValues, drawer, prevCompletedNode));
                return(nodePlus);
            }
            else
            {
                throw new Exception("Error while making Maclaurin serie: counter problem: " + counter);
            }
        }