internal static bool FuncCheck(double lb, double rb, double step, double coefA, double coefC) { DialogResult DR = new DialogResult(); int errCounter = 0; for (double i = lb; i <= rb; i += step) { double x = i; double y = GetValues.GetY(x, coefA, coefC); if (Double.IsNaN(y)) { errCounter++; } } if (errCounter != 0) { DR = MessageBox.Show("При таких значениях часть функции под корнем отрицательно. Не будет отображено точек: " + errCounter + ". Продолжить?", "Внимание!", MessageBoxButtons.OKCancel); if (DR == DialogResult.Cancel) { return(false); } } return(true); }
private void build_button_MouseClick(object sender, MouseEventArgs e) { dataTable.Rows.Clear(); Configurate.ChangeBG(); CassiniChart.Series[0].Points.Clear(); CassiniChart.Series[1].Points.Clear(); double.TryParse(leftBorder_tb.Text, out double lb); double.TryParse(rightBorder_tb.Text, out double rb); double.TryParse(step_tb.Text, out double step); double.TryParse(coefA_tb.Text, out double a); double.TryParse(coefC_tb.Text, out double c); double x; double y; if (AllTests.GoodToGo(lb, rb, step) && AllTests.FuncCheck(lb, rb, step, a, c)) { int size = Convert.ToInt32(Math.Abs((rb - lb) / step + 1)); double[] arrOfY = new double[size * 2]; int indexCounter = 0; for (double i = lb; i <= rb; i += step) { x = i; y = GetValues.GetY(x, a, c); CassiniChart.Series[0].Points.AddXY(x, y); CassiniChart.Series[1].Points.AddXY(x, -y); arrOfY[indexCounter] = y; indexCounter++; arrOfY[indexCounter] = -y; indexCounter++; if (!Double.IsNaN(y)) { // округление до 4 знаков после запятой и запись в dataGridView dataTable.Rows.Add(x, Configurate.ToFixed(y, (uint)DecimalPlaces.ForY)); dataTable.Rows.Add(x, -Configurate.ToFixed(y, (uint)DecimalPlaces.ForY)); } } CassiniChart.Hide(); if (AllTests.ValuesFit(arrOfY, lb, rb)) { CassiniChart.Show(); } ConfigurateChart(lb, rb, arrOfY); } }