private void selectSum(NodeHolder nh) { myDrawer.drawFunction(nh, true); lblHumanReadableString.Text = nh.GetHumanReadableString(); pbNodeStructure.ImageLocation = nh.CreateNodeStructurePicture(); lastSelectedFunction = nh; }
public NodeHolder GetDerivative() { Node StartNode = startNode.GetDerivative(); NodeHolder nh = new NodeHolder(StartNode); return(nh); }
private void btnCreateMaclaurinSerieAccurate_Click(object sender, EventArgs e) { int order; if (!int.TryParse(tbOrder.Text, out order)) { MessageBox.Show("Order needs to be an integer"); return; } try { if (lastSelectedFunction != null) { NodeHolder nh = lastSelectedFunction.GetMaclaurinSerieAccurate(order); selectSum(nh); myFunctions.Add(nh); lbFunctions.Items.Add(nh); lbFunctions.SelectedIndex = lbFunctions.Items.IndexOf(nh); } else { throw new Exception("No function has been selected"); } } catch (Exception ex) { MessageBox.Show("Error while making Maclaurin serie: " + ex.Message); } }
public void drawRienmann(NodeHolder function, int deltaX, double fromX, double toX) { //clearing previous function and setting up variables------------------------ lastDrawnFunction = function; this.fromX = fromX; this.toX = toX; this.deltaX = deltaX; bool newSerieHasBeenUsed = false; for (int i = 0; i < myChart.Series.Count; i++) { if (myChart.Series[i].Color == RienmannColor) { myChart.Series[i].Points.Clear(); } } rienmannHasBeenDrawn = false; int serieCounter = nextSerie(RienmannColor, -1); //drawing the new function------------------------------------------- double answerTemp; double totalDistance = (toX - fromX); double deltaDistance = totalDistance / deltaX; //niet nauwkeurig!! //double halfDeltaDistance = deltaDistance / 2; double XStartPosition; for (int i = 0; i < deltaX; i++) { //try //{ XStartPosition = fromX + i * deltaDistance; answerTemp = function.GetFunctionOutputForX(fromX + (totalDistance + totalDistance * i * 2) / (deltaX * 2)); if (answerTemp > myChart.ChartAreas[0].AxisY.Maximum) { answerTemp = myChart.ChartAreas[0].AxisY.Maximum + Math.Abs(myChart.ChartAreas[0].AxisY.Maximum) * 0.1; } if (answerTemp < myChart.ChartAreas[0].AxisY.Minimum) { answerTemp = myChart.ChartAreas[0].AxisY.Minimum - Math.Abs(myChart.ChartAreas[0].AxisY.Minimum) * 0.1; } myChart.Series[serieCounter].Points.AddXY(XStartPosition, 0); myChart.Series[serieCounter].Points.AddXY(XStartPosition, answerTemp); myChart.Series[serieCounter].Points.AddXY(XStartPosition + deltaDistance, answerTemp); myChart.Series[serieCounter].Points.AddXY(XStartPosition + deltaDistance, 0); myChart.Series[serieCounter].Points.AddXY(XStartPosition, 0); //} //catch //{ // if (newSerieHasBeenUsed) // { // serieCounter = nextSerie(functionColor, serieCounter); // newSerieHasBeenUsed = false; // } //} } rienmannHasBeenDrawn = true; }
public NodeHolder GetMaclaurinSerieAccurate(int order) { if (order <= 0) { throw new Exception("Order must be larger than 0"); } Node MaclaurinNode = getMaclaurinSerieRecursiveAccurate(1, order, startNode); NodeHolder MaclaurinNodeHolder = new NodeHolder(MaclaurinNode); return(MaclaurinNodeHolder); }
private void btnDerivativeByFunction_Click(object sender, EventArgs e) { if (lastSelectedFunction != null) { NodeHolder nh = lastSelectedFunction.GetDerivative(); selectSum(nh); myFunctions.Add(nh); lbFunctions.Items.Add(nh); lbFunctions.SelectedIndex = lbFunctions.Items.IndexOf(nh); } }
private void lbFunctions_SelectedIndexChanged(object sender, EventArgs e) { if (lbFunctions.SelectedIndex >= 0) { NodeHolder selected = (NodeHolder)lbFunctions.SelectedItem; selectSum(selected); } else { MessageBox.Show("No function has been selected"); } }
private void parseSum(string sum) { try { NodeHolder nh = new NodeHolder(sum); selectSum(nh); myFunctions.Add(nh); lbFunctions.Items.Add(nh); lbFunctions.SelectedIndex = lbFunctions.Items.IndexOf(nh); } catch (Exception ex) { MessageBox.Show("Parsing failed: " + ex.Message); } }
private void btnCalculatePoly_Click(object sender, EventArgs e) { if (points.Count / 2 >= 2) { try { NodeHolder nh = new NodeHolder(points); selectSum(nh); myFunctions.Add(nh); lbFunctions.Items.Add(nh); lbFunctions.SelectedIndex = lbFunctions.Items.IndexOf(nh); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("you need atleast 2 points in order to calculate the polynomial"); } }
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); } }
public void drawNewton(NodeHolder function) { //clearing previous function and setting up variables------------------------ lastDrawnFunction = function; bool newSerieHasBeenUsed = false; bool yBetweenMaxAndMin = false; bool previousAnswerWasPossible = false; double xDistance = myChart.ChartAreas[0].AxisX.Maximum / 1000; if (true) //FAST RENDER = false OR ACCURATE RENDER = true { xDistance = 0.01f; } for (int i = 0; i < myChart.Series.Count; i++) { if (myChart.Series[i].Color == newtonColor && myChart.Series[i].ChartType == SeriesChartType.Line) { myChart.Series[i].Points.Clear(); } } newtonHasBeenDrawn = false; int serieCounter = nextSerie(newtonColor, -1); //drawing the new function------------------------------------------- for (double i = myChart.ChartAreas[0].AxisX.Minimum; i <= myChart.ChartAreas[0].AxisX.Maximum; i += xDistance) { try { double answer = 0; answer = (function.GetFunctionOutputForX(i + 0.01f) - function.GetFunctionOutputForX(i)) / 0.01f; if (answer >= myChart.ChartAreas[0].AxisY.Minimum && answer <= myChart.ChartAreas[0].AxisY.Maximum) { myChart.Series[serieCounter].Points.AddXY(i, answer); //DRAW CURRENT if (previousAnswerWasPossible && !yBetweenMaxAndMin) //current point is between min/max, but previous was not, DRAW PREVIOUS { answer = (function.GetFunctionOutputForX(i - xDistance + 0.01f) - function.GetFunctionOutputForX(i - xDistance)) / 0.01f; myChart.Series[serieCounter].Points.AddXY(i - xDistance, answer); } newSerieHasBeenUsed = true; yBetweenMaxAndMin = true; } else if (yBetweenMaxAndMin) //previous answer was between max/min, DRAW ONE MORE AND START NEW SERIE { myChart.Series[serieCounter].Points.AddXY(i, answer); serieCounter = nextSerie(newtonColor, serieCounter); newSerieHasBeenUsed = false; yBetweenMaxAndMin = false; } else { if (newSerieHasBeenUsed) { serieCounter = nextSerie(newtonColor, serieCounter); newSerieHasBeenUsed = false; yBetweenMaxAndMin = false; } } previousAnswerWasPossible = true; } catch { if (newSerieHasBeenUsed) { serieCounter = nextSerie(newtonColor, serieCounter); newSerieHasBeenUsed = false; } previousAnswerWasPossible = false; } } newtonHasBeenDrawn = true; myChart.Invalidate(); }