Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double a, p, b, q, c, x0, x1, ex;
- if (textBox1.Text.Length == 0) a = 1;
- a = double.Parse(textBox1.Text);
- if (textBox2.Text.Length == 0) p = 1;
- p = double.Parse(textBox2.Text);
- if (textBox3.Text.Length == 0) b = 1;
- b = double.Parse(textBox3.Text);
- if (textBox4.Text.Length == 0) q = 1;
- q = double.Parse(textBox4.Text);
- if (textBox5.Text.Length == 0) c = 1;
- c = double.Parse(textBox5.Text);
- x0 = double.Parse(textBox6.Text);//Начальное значение
- x1 = double.Parse(textBox7.Text);//Начальное значение
- ex = double.Parse(textBox8.Text);//Точность
- double x = method_chord (x0, x1, ex, a, b, c, p, q);
- label9.Text = Convert.ToString (x);
- }
- //Черная коробка с вычислениями, использует метод function для вычисления
- public static double method_chord (double x_prev, double x_curr, double ex, double a, double b, double c, double p, double q)
- {
- double x_next = 0;
- double tmp;
- do {
- tmp = x_next;
- x_next = x_curr - function (x_curr, a, b, c, p, q) * (x_prev - x_curr) / (function (x_prev, a, b, c, p, q) - function (x_curr, a, b, c, p, q));
- x_prev = x_curr;
- x_curr = tmp;
- } while (Math.Abs (x_next - x_curr) > ex);
- return x_next;
- }
- //Метод с функцией, который проводите вычисления, принимает одно значение
- public static double function (double x, double a, double b, double c, double p, double q )
- {
- return a * (Math.Pow (x, p)) + b * (Math.Pow(x, q)) + c;
- }
- private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar <= 48 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
- e.Handled = true;
- }
- private void textBox2_KeyPress_1(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar <= 48 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
- e.Handled = true;
- }
- private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar <= 48 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
- e.Handled = true;
- }
- private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar <= 48 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
- e.Handled = true;
- }
- private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar <= 47 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
- e.Handled = true;
- }
- private void textBox6_KeyPress(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar <= 47 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
- e.Handled = true;
- }
- private void textBox7_KeyPress(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar <= 47 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
- e.Handled = true;
- }
- private void textBox8_KeyPress(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar <= 47 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
- e.Handled = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment