private void ProcessStatic() { PointPairList solution = new PointPairList(); solution.Add(new PointPair(curX, V)); for (int i = 0; (i < N) && (curX < maxX); i++) { V = Method(V, curX, H); curX += H; solution.Add(new PointPair(curX, V)); } // Draw points GraphPane pane = MainGraph.GraphPane; if (ReloadCheckBox.Checked) { pane.CurveList.Clear(); } pane.AddCurve("Решение c постоянным шагом", solution, Color.FromArgb(random.Next() % 256, random.Next() % 256, random.Next() % 256), SymbolType.None); MainGraph.AxisChange(); MainGraph.Refresh(); }
private void DrawIntegral() { PointPairList pairListHit = new PointPairList(); PointPairList pairListNoHit = new PointPairList(); double function_result; double d = FindMaximum(); double c = FindMinimum(); double x; double y; for (uint i = 0; i < N; ++i) { x = a + random.NextDouble() * (b - a); y = c + random.NextDouble() * (d - c); function_result = Function(x); if (0 > function_result) { if (0 > y && function_result <= y) { pairListHit.Add(new PointPair(x, y)); } else { pairListNoHit.Add(new PointPair(x, y)); } } else { if (0 <= y && function_result >= y) { pairListHit.Add(new PointPair(x, y)); } else { pairListNoHit.Add(new PointPair(x, y)); } } } LineItem hitCurve = pane.AddCurve("Hit", pairListHit, Color.Green, SymbolType.Plus); hitCurve.Line.IsVisible = false; LineItem noHitCurve = pane.AddCurve("Not hit", pairListNoHit, Color.Red, SymbolType.Circle); noHitCurve.Line.IsVisible = false; MainGraph.Hide(); MainGraph.AxisChange(); MainGraph.Show(); }
private void DrawFunction() { PointPairList pairList = new PointPairList(); PointPair pair = new PointPair(); for (double x = a; x < b; x += (b - a) / N) { pair.X = x; pair.Y = Function(x); pairList.Add(pair); } pane.AddCurve("Function", pairList, Color.Black, SymbolType.None); MainGraph.Hide(); MainGraph.AxisChange(); MainGraph.Show(); }
private void ProcessExact() { PointPairList solution = new PointPairList(); double startI = V; double startX = curX; List <List <double> > table = new List <List <double> >(); List <double> row = new List <double>(11); solution.Add(new PointPair(startX, startI)); table.Add(new List <double>() { 0, H, startX, startI }); for (int i = 0; (i < N) && (startX < maxX); i++) { row.Clear(); startI = Method(startI, startX, H); startX += H; solution.Add(new PointPair(startX, startI)); row.Add(i + 1); row.Add(H); row.Add(startX); row.Add(startI); table.Add(new List <double>(row)); } // Fill table DataGridViewRowCollection rows = ExactTable.Rows; rows.Clear(); for (int i = 0; i < table.Count; ++i) { rows.Add(); for (int j = 0; j < table[i].Count; ++j) { rows[i].Cells[j].Value = table[i][j]; } } // Fill last dot DataGridViewRowCollection lastDotRow = LastDotTable.Rows; lastDotRow.Clear(); if (0 < table.Count) { lastDotRow.Add(); for (int i = 0; i < lastDotRow[0].Cells.Count; ++i) { lastDotRow[0].Cells[i].Value = rows[rows.Count - 1].Cells[i].Value; } } // Draw points GraphPane pane = MainGraph.GraphPane; if (ReloadCheckBox.Checked) { pane.CurveList.Clear(); } pane.AddCurve("Точное решение", solution, Color.FromArgb(random.Next() % 256, random.Next() % 256, random.Next() % 256), SymbolType.None); MainGraph.AxisChange(); MainGraph.Refresh(); }
private void ProcessDynamic() { PointPairList solutionWithHalfStep = new PointPairList(); List <List <double> > table = new List <List <double> >(); List <double> row = new List <double>(11); List <double> Slist = new List <double>(); List <double> Xlist = new List <double>(); double Hprev = H; double Vstep = V; double Vhalf; double Vprev; double S; uint C1 = 0u; uint C2 = 0u; uint totalC1 = 0u; uint totalC2 = 0u; // step #0 table.Add(new List <double>() { 0, 0, curX, Vstep, Vstep, 0, 0, 0, 0 }); solutionWithHalfStep.Add(new PointPair(curX, Vstep)); // using control for (uint i = 1u; (i <= N);) { // Save previous result Vprev = Vstep; Hprev = H; Vstep = Method(Vprev, curX, H); Vhalf = Method(Vprev, curX, H * 0.5); Vhalf = Method(Vhalf, curX + (H * 0.5), H * 0.5); S = (Vhalf - Vstep) / (Math.Pow(2.0, 4.0) - 1.0); if (Math.Abs(S) > eps) { H *= 0.5; Vstep = Vprev; C1++; continue; } else { curX += H; if (Math.Abs(S) <= (eps / Math.Pow(2.0, 5.0))) { H *= 2.0; C2++; } } Slist.Add(S); Xlist.Add(curX); // fill the graph solutionWithHalfStep.Add(new PointPair(curX, Vhalf)); // Create table row.Clear(); // index row.Add(i); // current step row.Add(Hprev); // x value row.Add(curX); // v value with step row.Add(Vstep); // v value with half step row.Add(Vhalf); // difference between them row.Add(Vstep - Vhalf); // S row.Add(S); // number of step doubles row.Add(C1); //number of step divisions in half row.Add(C2); // store row table.Add(new List <double>(row)); if (curX >= maxX) { break; } // Update fields i++; totalC1 += C1; totalC2 += C2; C1 = 0u; C2 = 0u; } // Draw points GraphPane pane = MainGraph.GraphPane; if (ReloadCheckBox.Checked) { pane.CurveList.Clear(); } pane.AddCurve("Решение с половинным шагом", solutionWithHalfStep, Color.FromArgb(random.Next() % 256, random.Next() % 256, random.Next() % 256), SymbolType.None); MainGraph.AxisChange(); MainGraph.Refresh(); // Fill table DataGridViewRowCollection rows = MainTable.Rows; rows.Clear(); for (int i = 0; i < table.Count; ++i) { rows.Add(); for (int j = 0; j < table[i].Count; ++j) { rows[i].Cells[j].Value = table[i][j]; } } // Fill last dot DataGridViewRowCollection lastDotRow = LastDotTable.Rows; lastDotRow.Clear(); if (0 < table.Count) { lastDotRow.Add(); for (int i = 0; i < lastDotRow[0].Cells.Count; ++i) { lastDotRow[0].Cells[i].Value = rows[rows.Count - 1].Cells[i].Value; } } if ((0 == Slist.Count) || (0 == Xlist.Count)) { return; } // Fill reference double minS = Math.Abs(Slist[0]); double maxS = Math.Abs(Slist[0]); double maxSx = Xlist[0]; double minSx = Xlist[0]; for (int i = 1; i < Slist.Count; ++i) { if (Math.Abs(Slist[i]) > maxS) { maxS = Math.Abs(Slist[i]); maxSx = Xlist[i]; } if (Math.Abs(Slist[i]) < minS) { minS = Math.Abs(Slist[i]); minSx = Xlist[i]; } } minSLabel.Text = "min |S| = " + minS.ToString() + "\nв точке x = " + minSx.ToString(); maxSLabel.Text = "max |S| = " + maxS.ToString() + "\nв точке x = " + maxSx.ToString(); IncLabel.Text = "Ув. шага = " + totalC2.ToString(); DecLabel.Text = "Ум. шага = " + totalC1.ToString(); }