MainFunction funk = new MainFunction();     //We get function from this

        public bool CheckInterval(float a, float b) // interval has same signs at each end
        {
            if (Math.Sign(funk.Function(a)) == Math.Sign(funk.Function(b)))
            {
                return(true);  //signs are the same
            }
            return(false);
        }
Exemple #2
0
 public void DoAlgoritm()
 {
     if (!algorithms.CheckInterval(variables.A, variables.B))               //checks interval if signs are different
     {
         var c      = algorithms.FindCenterPoint(variables.A, variables.B); //gets center point
         var answer = funk.Function(c);                                     //gets f(c) answer
         if (algorithms.IsAnswerSmallerEpsilon(answer, variables.epsilon))  //checks if f(c) answer is smaller than epsilon if true stops iteration
         {
             variables.IsAnswerGood = false;
         }
         if (answer == 0)
         {
             Print(_iteration++, variables.A, variables.B, c, answer);
             return;
         }
         if (algorithms.CheckInterval(c, variables.A)) //check interval signs
         {
             Print(_iteration++, variables.A, variables.B, c, answer);
             variables.A = c;  // c and A are on the same side (have same signs)
         }
         else
         {
             Print(_iteration++, variables.A, variables.B, c, answer);
             variables.B = c; // c and A have different signs
         }
     }
 }
        public float CountingNewPoint(float a, float b)  //finding new point
        {
            float newPoint;
            var   temp1 = b - a;
            var   temp2 = funk.FunctionForTwo(a, b);

            temp1    = temp1 / temp2;
            temp2    = funk.Function(b);
            newPoint = b - temp2 * temp1;
            return(newPoint);
        }
Exemple #4
0
 public void MainSecant()
 {
     while (true)
     {
         var temp = algorithm.CountingNewPoint(variables.A, variables.B); //finds new point
         variables.A = variables.B;
         variables.B = temp;
         temp        = funk.Function(variables.B);
         Print(variables.A, variables.B, temp);
         i++;
         if (algorithm.CheckPrecision(variables.A, variables.B, variables.epsilon) || i == 100)
         {
             break;
         }
     }
 }