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 GetDerivative() //O = original, D = derivative { Node node1O1 = node1.Clone(); Node node1D = node1.GetDerivative(); Node node2O1 = node2.Clone(); Node nodeTimes1 = new NodeTimes(); Node nodeTimes2 = new NodeTimes(); if (node2.ContainsX()) { Node thisNode = this.Clone(); Node node1O2 = node1.Clone(); Node node2D = node2.GetDerivative(); Node nodePlus = new NodePlus(); Node nodeLN = new NodeLN(); Node nodeDiv = new NodeDivision(); Node nodeTimes3 = new NodeTimes(); nodeTimes3.AddNode1(thisNode); nodeTimes3.AddNode2(nodePlus); nodePlus.AddNode1(nodeTimes1); nodePlus.AddNode2(nodeTimes2); nodeTimes1.AddNode1(node1D); nodeTimes1.AddNode2(nodeDiv); nodeDiv.AddNode1(node2O1); nodeDiv.AddNode2(node1O1); nodeTimes2.AddNode1(node2D); nodeTimes2.AddNode2(nodeLN); nodeLN.AddNode1(node1O2); return(nodeTimes3); } else { Node node2O2 = node2.Clone(); Node nodeNumberOne = new NodeNumber(false, false, 1); Node nodeMin = new NodeMinus(); Node nodePow = new NodePower(); nodeTimes2.AddNode1(nodePow); nodeTimes2.AddNode2(nodeTimes1); nodeTimes1.AddNode1(node2O1); nodeTimes1.AddNode2(node1D); nodePow.AddNode1(node1O1); nodePow.AddNode2(nodeMin); nodeMin.AddNode1(node2O2); nodeMin.AddNode2(nodeNumberOne); return(nodeTimes2); } }
public override Node GetDerivative() //O = original, D = derivative { Node nodePlus = new NodePlus(); Node node1D = node1.GetDerivative(); Node node2D = Node2.GetDerivative(); nodePlus.AddNode1(node1D); nodePlus.AddNode2(node2D); return(nodePlus); }
public override Node Clone() { Node newNode = new NodePlus(); Node newNode1 = node1.Clone(); Node newNode2 = node2.Clone(); newNode.AddNode1(newNode1); newNode1.AddParentNode(newNode); newNode.AddNode2(newNode2); newNode2.AddParentNode(newNode); return(newNode); }
public override Node MakeNodeClean(Node prevNodeNumber, out Node replacementNode) { Node garbage; if (node1 is NodeLN && node2 is NodeLN) //exception { Node nodeDiv = new NodeDivision(); Node nodeln = new NodeLN(); nodeln.AddNode1(nodeDiv); nodeDiv.AddNode1(Node1.Node1); nodeDiv.AddNode2(node2.Node1); nodeln.MakeNodeClean(null, out garbage); replacementNode = null; return(nodeln); } else { Node nodePlus = new NodePlus(); nodePlus.AddNode1(node1); if (node2 is NodeNumber) { ((NodeNumber)node2).SwapPositivity(); nodePlus.AddNode2(node2); } else if (node2 is NodeMinus) { Node newNode2 = node2.MakeNodeClean(null, out garbage); //node2 is now nodeplus ((NodePlus)newNode2).SwapPositivity(); nodePlus.AddNode2(newNode2); } else { Node nodeTimes = new NodeTimes(); Node nodeNumber = new NodeNumber(false, false, -1); nodeTimes.AddNode1(nodeNumber); nodeTimes.AddNode2(node2); nodePlus.AddNode2(nodeTimes); } replacementNode = null; nodePlus.MakeNodeClean(null, out garbage); return(nodePlus); } }
public override Node GetDerivative() //O = original, D = derivative { Node nodePlus = new NodePlus(); Node nodeTimes1 = new NodeTimes(); Node nodeTimes2 = new NodeTimes(); Node node1O = node1.Clone(); Node node1D = node1.GetDerivative(); Node node2O = node2.Clone(); Node node2D = node2.GetDerivative(); nodePlus.AddNode1(nodeTimes1); nodePlus.AddNode2(nodeTimes2); nodeTimes1.AddNode1(node1D); nodeTimes1.AddNode2(node2O); nodeTimes2.AddNode1(node2D); nodeTimes2.AddNode2(node1O); return(nodePlus); }
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); } }
private Node combineNodes(Node cleanNode1, Node cleanNode2, bool bothAreUpperNodes) { if (!bothAreUpperNodes) { if (!(cleanNode1 is NodeNumber) && cleanNode2 is NodeNumber) { if (((NodeNumber)cleanNode2).Number == 0) { Node newNumberNode; newNumberNode = new NodeNumber(false, false, 1); return(newNumberNode); } } if (cleanNode1 is NodeNumber && cleanNode2 is NodeNumber) { if (((NodeNumber)cleanNode2).Number == 0 && ((NodeNumber)cleanNode1).Number != 0) { Node newNumberNode; newNumberNode = new NodeNumber(false, false, 1); return(newNumberNode); } else if (!cleanNode1.ContainsX() && !cleanNode2.ContainsX()) { if (!cleanNode1.ContainsP() && !cleanNode2.ContainsP()) { Node newNumberNode; newNumberNode = new NodeNumber(false, false, Math.Pow(((NodeNumber)cleanNode1).Number, ((NodeNumber)cleanNode2).Number)); return(newNumberNode); } } else if (((NodeNumber)cleanNode2).Number == 1) { return(cleanNode1); } } //none of the nodes are numbers, so they need to be cleaned! Node trash; if (cleanNode1 is NodeLN) { Node nodePow = new NodePower(); nodePow.AddNode1(cleanNode1.Node1); nodePow.AddNode2(cleanNode2); cleanNode1.AddNode1(nodePow); cleanNode1.MakeNodeClean(null, out trash); return(cleanNode1); } if (cleanNode1 is NodeE) { Node nodePlus = new NodePlus(); nodePlus.AddNode1(cleanNode1.Node1); nodePlus.AddNode2(cleanNode2); cleanNode1.AddNode1(nodePlus); cleanNode1.MakeNodeClean(null, out trash); return(cleanNode1); } } else //both are upper nodes, try to multiply time if possible (this is a copy of nodeTimes.combineNodes() method) { if (cleanNode1 is NodeNumber && cleanNode2 is NodeNumber) { if (cleanNode1.ContainsX() != cleanNode2.ContainsX()) //one has X { if (cleanNode1.ContainsP() != cleanNode2.ContainsP()) //one has P { Node newNumberNode; newNumberNode = new NodeNumber(true, true, ((NodeNumber)cleanNode1).Number * ((NodeNumber)cleanNode2).Number); return(newNumberNode); } else if (!cleanNode1.ContainsP()) //both have not P { Node newNumberNode; newNumberNode = new NodeNumber(true, false, ((NodeNumber)cleanNode1).Number * ((NodeNumber)cleanNode2).Number); return(newNumberNode); } } else if (!cleanNode1.ContainsX()) //both have not X { if (cleanNode1.ContainsP() != cleanNode2.ContainsP()) //one has P { Node newNumberNode; newNumberNode = new NodeNumber(false, true, ((NodeNumber)cleanNode1).Number * ((NodeNumber)cleanNode2).Number); return(newNumberNode); } else if (!cleanNode1.ContainsP()) //both have not P { Node newNumberNode; newNumberNode = new NodeNumber(false, false, ((NodeNumber)cleanNode1).Number * ((NodeNumber)cleanNode2).Number); return(newNumberNode); } } } } return(null); }
private Node combineNodes(Node cleanNode1, Node cleanNode2) { if (cleanNode1 is NodeNumber && !(cleanNode2 is NodeNumber)) { if (((NodeNumber)cleanNode1).Number == 0) { Node newNumberNode; newNumberNode = new NodeNumber(false, false, 0); return(newNumberNode); } else if (((NodeNumber)cleanNode1).Number == 1 && !cleanNode1.ContainsX() && !cleanNode1.ContainsP()) { return(cleanNode2); } else if (cleanNode2 is NodePower) { if (cleanNode2.Node1 is NodeNumber) { if (((NodeNumber)cleanNode1).ContainsX() == ((NodeNumber)cleanNode2.Node1).ContainsX()) { //check if nodePower.Node1(lower) has only 1x and node has (somenumber)x } } } } if (cleanNode2 is NodeNumber && !(cleanNode1 is NodeNumber)) { if (((NodeNumber)cleanNode2).Number == 0) { Node newNumberNode; newNumberNode = new NodeNumber(false, false, 0); return(newNumberNode); } else if (((NodeNumber)cleanNode2).Number == 1 && !cleanNode2.ContainsX() && !cleanNode2.ContainsP()) { return(cleanNode1); } } if (cleanNode1 is NodeNumber && cleanNode2 is NodeNumber) { if (cleanNode1.ContainsX() != cleanNode2.ContainsX()) //one has X { if (cleanNode1.ContainsP() != cleanNode2.ContainsP()) //one has P { Node newNumberNode; newNumberNode = new NodeNumber(true, true, ((NodeNumber)cleanNode1).Number * ((NodeNumber)cleanNode2).Number); return(newNumberNode); } else if (!cleanNode1.ContainsP()) //both have not P { Node newNumberNode; newNumberNode = new NodeNumber(true, false, ((NodeNumber)cleanNode1).Number * ((NodeNumber)cleanNode2).Number); return(newNumberNode); } } else if (!cleanNode1.ContainsX()) //both have not X { if (cleanNode1.ContainsP() != cleanNode2.ContainsP()) //one has P { Node newNumberNode; newNumberNode = new NodeNumber(false, true, ((NodeNumber)cleanNode1).Number * ((NodeNumber)cleanNode2).Number); return(newNumberNode); } else if (!cleanNode1.ContainsP()) //both have not P { Node newNumberNode; newNumberNode = new NodeNumber(false, false, ((NodeNumber)cleanNode1).Number * ((NodeNumber)cleanNode2).Number); return(newNumberNode); } } } //none of the nodes are numbers, so they need to be cleaned! Node trash; if (cleanNode2.SameAs(cleanNode1)) { Node nodePow = new NodePower(); nodePow.AddNode1(cleanNode1); nodePow.AddNode2(new NodeNumber(false, false, 2)); nodePow.MakeNodeClean(null, out trash); return(nodePow); } if ((cleanNode1 is NodePower && cleanNode2 is NodePower) || (cleanNode1 is NodeE && cleanNode2 is NodeE) || (cleanNode1 is NodeLN && cleanNode2 is NodeLN)) { if (cleanNode1.Node1.SameAs(cleanNode2.Node1)) { if (cleanNode1 is NodePower) { Node nodePow = new NodePower(); Node nodePlus = new NodePlus(); nodePow.AddNode1(cleanNode1.Node1); nodePow.AddNode2(nodePlus); nodePlus.AddNode1(cleanNode1.Node2); nodePlus.AddNode2(cleanNode2.Node2); nodePow.MakeNodeClean(null, out trash); return(nodePow); } } if (cleanNode1 is NodeE) { Node nodeE = new NodeE(); Node nodePlus = new NodePlus(); nodeE.AddNode1(nodePlus); nodePlus.AddNode1(cleanNode1.Node1); nodePlus.AddNode2(cleanNode2.Node1); nodeE.MakeNodeClean(null, out trash); return(nodeE); } } return(null); }