Facebook
From karol, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 254
  1.    public  class SecondMethod
  2.     {
  3.         protected double a, b, epsilon, n_iteration, c, count = 1;
  4.         protected Form2 form;
  5.         protected Argument x_epresion;
  6.         protected Expression e;
  7.         string expression;
  8.         public SecondMethod(string expression, Form2 form, double a, double b, double epsilon) {
  9.        
  10.             this.a = a;
  11.             this.b = b;
  12.             this.epsilon = epsilon;
  13.             this.expression = expression;
  14.             this.form = form;
  15.         }
  16.         public double f(double x)
  17.         {
  18.             x_epresion = new Argument("x",x);
  19.             e = new Expression(expression, x_epresion);
  20.          //   this.form.textBox3.AppendText("UWAGA pochodna wynosi"+ directive(1));
  21.             return e.calculate();
  22.         }
  23.         double directive(double f_value)
  24.         {
  25.             Argument x_epresion = new Argument("x", f_value);
  26.             string a = "der(" + e.getExpressionString() + ", x)";
  27.  
  28.  
  29.             Function f = new Function("f(x) = " + a);
  30.             e = new Expression("f(" + f_value.ToString() + ")", f);
  31.  
  32.  
  33.             e = new Expression(a, x_epresion);
  34.             return e.calculate();
  35.         }
  36.         public virtual double search()
  37.         {
  38.             do
  39.             {
  40.                 if (f(a) == f(b))
  41.                 {
  42.                     return -1;
  43.                 }
  44.                 c = (a * f(b) - b * f(a)) / (f(b) - f(a));
  45.                 this.form.textBox3.AppendText("pochodna wynosi " + f(c).ToString());
  46.                 a = b;
  47.                 b = c;
  48.                 var napis = String.Format("Iteration {0}    x={1}\n", count, c, 2);
  49.                 this.form.textBox2.AppendText(napis);
  50.                 count++;
  51.                 if (count == 100)
  52.                 {
  53.                     return c;
  54.                 }
  55.  
  56.             } while (Math.Abs(f(c)) > epsilon);
  57.             return c;
  58.         }
  59.     }