private void AutoFindRoots() { float x1, x2; double eps; errorProvider.Clear(); try { eps = float.Parse(textE.Text); } catch (FormatException) { errorProvider.SetError(textE, "Wrong float number"); return; } if (eps < 0) { errorProvider.SetError(textE, "Has to be > 0"); return; } try { x1 = float.Parse(textX1.Text); } catch (FormatException) { errorProvider.SetError(textX1, "Wrong float number"); return; } try { x2 = float.Parse(textX2.Text); } catch (FormatException) { errorProvider.SetError(textX2, "Wrong float number"); return; } float step = (x2 - x1) / 100f; DekartForm dForm; dForm = new DekartForm(100, 100, 175, 300); dForm.Use_IsVisible = false; dForm.Size = new Size(350, 600); dForm.CenterView(); listRoots.Items.Clear(); listY.Items.Clear(); roots = new List <double>(); for (float x = x1; x < x2; x += step) { double res = double.NaN; List <PointF[]> lines = null; switch (selectedSolMeth) { #region Method Still Point case SolutionMethod.StillPoint: if (dForm.CountGraphics == 0) { dForm.AddGraphic(g, -5f, 5f, DrawModes.DrawLines, Color.Green); dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Gray); dForm.AddGraphic(bisectress, -5f, 5f, DrawModes.DrawLines, Color.Blue); } res = FindRoot.StillPointMethod(h, x, eps, out lines, true); break; #endregion #region Method Bisection case SolutionMethod.Bisection: if (dForm.CountGraphics == 0) { dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green); } res = FindRoot.Bisection(h, x, x + step, eps, out lines, true); break; #endregion //#region Method Newtone-Rafson //case SolutionMethod.NewtoneRafson: // MessageBox.Show("How to evaluate dh/dx?"); // return; // if ( dForm.CountGraphics == 0 ) // dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green); // res = FindRoot.NewtoneRafson(f, df, x, eps, out lines); // break; //#endregion #region Method Cuttings case SolutionMethod.Cuttings: if (dForm.CountGraphics == 0) { dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green); } res = FindRoot.Cuttings(h, x, x + step, eps, out lines, true); break; #endregion //#region Method Hord //case SolutionMethod.Hord: // if ( dForm.CountGraphics == 0 ) // dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green); // res = FindRoot.Hord(f, d2f, x, x + step, eps, out lines); // break; //#endregion #region Method Muller case SolutionMethod.Muller: if (dForm.CountGraphics == 0) { dForm.AddGraphic(f, -5f, 5f, DrawModes.DrawLines, Color.Green); } res = FindRoot.Muller(h, x - step, x, x + step, eps, ref dForm, true); lines = null; break; #endregion default: return; } if (lines != null) { foreach (PointF[] pts in lines) { dForm.AddPolygon(Color.Red, DrawModes.DrawLines, pts); } } if (double.IsNaN(res)) { continue; } if ((res > x2) || (res < x1)) { continue; } roots.Add(res); } roots.Sort(); foreach (double p in roots) { listRoots.Items.Add("x" + (listRoots.Items.Count + 1) + " = " + p.ToString("F16")); listY.Items.Add("y" + (listY.Items.Count + 1) + " = " + f(p).ToString("F16")); } dForm.Show(); dForm.Update2(); }