fr0stn1k

ChordMethodGui

Dec 23rd, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.67 KB | None | 0 0
  1. double a, p, b, q, c, x0, x1, ex;
  2.  
  3.             if (textBox1.Text.Length == 0) a = 1;
  4.             a = double.Parse(textBox1.Text);
  5.             if (textBox2.Text.Length == 0) p = 1;
  6.             p = double.Parse(textBox2.Text);
  7.             if (textBox3.Text.Length == 0) b = 1;
  8.             b = double.Parse(textBox3.Text);
  9.             if (textBox4.Text.Length == 0) q = 1;
  10.             q = double.Parse(textBox4.Text);
  11.             if (textBox5.Text.Length == 0) c = 1;
  12.             c = double.Parse(textBox5.Text);
  13.             x0 = double.Parse(textBox6.Text);//Начальное значение
  14.             x1 = double.Parse(textBox7.Text);//Начальное значение
  15.             ex = double.Parse(textBox8.Text);//Точность
  16.             double x = method_chord (x0, x1, ex, a, b, c, p, q);
  17.             label9.Text = Convert.ToString (x);
  18.         }
  19.            
  20.  
  21.         //Черная коробка с вычислениями, использует метод function для вычисления
  22.         public static double method_chord (double x_prev, double x_curr, double ex, double a, double b, double c, double p, double q)
  23.         {
  24.             double x_next = 0;
  25.             double tmp;
  26.  
  27.             do {
  28.                 tmp = x_next;
  29.                 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));
  30.                 x_prev = x_curr;
  31.                 x_curr = tmp;
  32.             } while (Math.Abs (x_next - x_curr) > ex);
  33.  
  34.             return x_next;
  35.         }
  36.         //Метод с функцией, который проводите вычисления, принимает одно значение
  37.         public static double function (double x, double a, double b, double c, double p, double q )
  38.         {
  39.             return  a * (Math.Pow (x, p)) + b * (Math.Pow(x, q)) + c;
  40.         }
  41.  
  42.         private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  43.         {
  44.             if ((e.KeyChar <= 48 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
  45.                 e.Handled = true;
  46.         }
  47.  
  48.         private void textBox2_KeyPress_1(object sender, KeyPressEventArgs e)
  49.         {
  50.             if ((e.KeyChar <= 48 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
  51.                 e.Handled = true;
  52.         }
  53.  
  54.         private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
  55.         {
  56.             if ((e.KeyChar <= 48 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
  57.                 e.Handled = true;
  58.         }
  59.  
  60.         private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
  61.         {
  62.             if ((e.KeyChar <= 48 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
  63.                 e.Handled = true;
  64.         }
  65.  
  66.         private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
  67.         {
  68.             if ((e.KeyChar <= 47 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
  69.                 e.Handled = true;
  70.         }
  71.  
  72.         private void textBox6_KeyPress(object sender, KeyPressEventArgs e)
  73.         {
  74.             if ((e.KeyChar <= 47 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
  75.                 e.Handled = true;
  76.         }
  77.  
  78.         private void textBox7_KeyPress(object sender, KeyPressEventArgs e)
  79.         {
  80.             if ((e.KeyChar <= 47 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
  81.                 e.Handled = true;
  82.         }
  83.  
  84.         private void textBox8_KeyPress(object sender, KeyPressEventArgs e)
  85.         {
  86.             if ((e.KeyChar <= 47 || e.KeyChar >= 58) && (e.KeyChar != 8 && e.KeyChar != 45))
  87.                 e.Handled = true;
  88.         }
Advertisement
Add Comment
Please, Sign In to add comment