private void tool_f_Click(object sender, EventArgs e) { try { a = float.Parse(textBoxA.Text); b = float.Parse(textBoxB.Text); } catch (FormatException) { MessageBox.Show("Parsing error, aborted."); return; } if ((!checkBoxReuse.Checked) || (dForm == null)) { dForm = new DekartForm(100, 100, 50, 400); dForm.Size = new Size(440, 540); } else { dForm.RemoveAllGraphics(); } dForm.Text = "Green - f(x)"; dForm.AddGraphic(new DoubleFunction(f), a, b, DrawModes.DrawLines, Color.Green); dForm.Show(); }
private void FindRoot() { double res = double.NaN; List <PointF[]> lines = null; #region prepare dform if (dForm == null) { dForm = new DekartForm(100, 100, 300, 300); dForm.Size = new Size(750, 600); dForm.Use_IsVisible = false; dForm.toolStripContainer1.ContentPanel.MouseUp += new MouseEventHandler(dForm_MouseClick); dForm.FormClosed += new FormClosedEventHandler(delegate(object s, FormClosedEventArgs eva) { ReadPolynom(); textBoxFx.Text = poly1.ToString(); dForm = null; }); } else { dForm.RemoveAllGraphics(); } #endregion dForm.AddGraphic(f, x1, x2, DrawModes.DrawLines, Color.Green); dForm.Show(); dForm.Update2(); res = NewtoneRafson(f, df, p0, eps, out lines, false); lastRoot = res; #region Print results if (lines != null) { foreach (PointF[] pts in lines) { dForm.AddPolygon(Color.Red, DrawModes.DrawLines, pts); } } dForm.Update2(); if (double.IsNaN(res)) { dForm.Text = "Корни не найдены."; return; } listRoots.Items.Add("x" + (listRoots.Items.Count + 1) + " = " + res.ToString("F16")); listY.Items.Add("y" + (listY.Items.Count + 1) + " = " + poly1.Evaluate(res).ToString("F16")); #endregion }
private void FindRoot() { Complex res = Complex.NaN; #region prepare dform if (dForm == null) { dForm = new DekartForm(100, 100, 300, 300); dForm.ClientSize = new Size(600, 600); dForm.Use_IsVisible = false; dForm.FormClosed += new FormClosedEventHandler(delegate(object s, FormClosedEventArgs eva) { dForm = null; }); } else { dForm.RemoveAllGraphics(); } #endregion List <Root> roots = new List <Root>(); List <PointF> pts = new List <PointF>(); List <Color> colors = new List <Color>(); Color[] baseColors = new Color[] { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.LightBlue, Color.Blue, Color.Violet }; double y1 = x1, y2 = x2; DoubleOfVectorFunction[] dovf = new DoubleOfVectorFunction[] { f1, f2 }; Complex c = new Complex(0); for (double y = y1; y < y2; y += hy) { for (double x = x1; x < x2; x += hx) { int iterations; float percent; c.re = x; c.im = y; res = Newtone(dovf, c, eps, out iterations); bool inRange = true; inRange &= res.re > x1; inRange &= res.re < x2; inRange &= res.im > y1; inRange &= res.im < y2; if (Complex.IsNaN(res) || !inRange) { colors.Add(Color.Black); pts.Add(new PointF((float)x, (float)y)); } else { if (roots.Count == 0) { Root newRoot; newRoot.color = baseColors[roots.Count % baseColors.Length]; newRoot.value = res; roots.Add(newRoot); } percent = iterations / 15f; if (percent > 1f) { percent = 1f; } bool needAdd = true; foreach (Root r in roots) { if (Near(r.value, res)) { colors.Add(ColorModifer.Brightness(r.color, percent)); pts.Add(new PointF((float)x, (float)y)); needAdd = false; break; } } if (needAdd) { Root newRoot; newRoot.color = baseColors[roots.Count % baseColors.Length]; newRoot.value = res; roots.Add(newRoot); colors.Add(ColorModifer.Brightness(newRoot.color, percent)); pts.Add(new PointF((float)x, (float)y)); } } } } DotGraphic dotGraphic = new DotGraphic(pts.ToArray(), colors.ToArray()); dotGraphic.CurrentColorSchema = new MathGraphic.ColorSchema( Color.Black, Color.DimGray, Color.DimGray, Color.Gray); dForm.AddGraphic(dotGraphic); MathGraphic mg; mg = new MathGraphic(Color.White, DrawModes.DrawLines, f1x, f1y, -5f, 5f, 0.01f); dForm.AddGraphic(mg); mg = new MathGraphic(Color.White, DrawModes.DrawLines, f2x, f2y, -5f, 5f, 0.01f); dForm.AddGraphic(mg); dForm.Show(); dForm.Update2(); foreach (Root z in roots) { listRoots.Items.Add("z" + (listRoots.Items.Count + 1) + " = " + z.value.ToString("F6")); listY.Items.Add("f,g" + (listY.Items.Count + 1) + " = " + f1(z.value.re, z.value.im).ToString("F6") + ", " + f2(z.value.re, z.value.im).ToString("F6")); } }
private void графическийМетодToolStripMenuItem_Click(object sender, EventArgs e) { try { DowndateGrid(); } catch { MessageBox.Show("Input error!"); return; } if (df != null) { df.RemoveAllGraphics(); } richTextBox1.Text = ""; GraphicSolver solver = new GraphicSolver(); solver.DebugPolygon += new GraphicSolver.DebugPolygonEventHandler(solver_DebugPolygonEvent); solver.DebugMaxMinPts += new GraphicSolver.DebugMaxMinEventHandler(solver_DebugMaxMin); solver.DebugMaxSolution += new GraphicSolver.DebugExtremumEventHandler(solver_DebugMaxSolution); solver.DebugMinSolution += new GraphicSolver.DebugExtremumEventHandler(solver_DebugMinSolution); solver.DebugGaussProcessMatrix += new GraphicSolver.DebugGaussProcessMatrixHandler(solver_DebugGaussProcessMatrix); for (int i = 0; i < A.Length; i++) { solver.AddLimtation(A[i], S[i], B[i]); } solver.SetTargetFunctionCoefficients(C); //solver_DebugGaussProcessMatrix((Fraction[,])A); formTables = new FormSTables(); try { solver.Solve(); } catch (InvalidOperationException exc) { MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } #region specialno dlya djema))) podrobnosti richTextBox1.Text += " ---===== Детали ====--- " + Environment.NewLine; for (int i = 0; i < m; i++) { richTextBox1.Text += string.Format( " x{0} = {1}·x1 {2} {3}·x2 {4} {5}", // x3 = 4/5·x1 + 1/2·x2 - 7/5 i + 1, // 0 -solver.A[i, 1], // 1 Math.Sign(-solver.A[i, 2]) < 0 ? "" : "+", // 2 -solver.A[i, 2], // 3 Math.Sign(solver.A[i, 0]) < 0 ? "" : "+", // 4 solver.A[i, 0] // 5 ) + Environment.NewLine; } // F(x1,x2) = c1x1 + c2x2 + d richTextBox1.Text += string.Format( " F = {0}·x1 {1} {2}·x2 {3} {4}", // e.g.: F = 4/5·x1 + 1/2·x2 - 7/5 solver.C1, // 0 Math.Sign(solver.C2) < 0 ? "" : "+", // 1 solver.C2, // 2 Math.Sign(solver.D) < 0 ? "" : "+", // 3 solver.D // 4 ) + Environment.NewLine; #endregion }