Facebook
From Mature Gibbon, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 266
  1. void bisekcja(double a, double b, double epsilon) {
  2.  
  3.     cout <<endl<<endl;
  4.     cout << "Metoda bisekcji"<<endl;
  5.     cout << "a = " <<a<<endl;
  6.     cout << "b = " <<b<<endl;
  7.  
  8.     double s;
  9.     int i=0;
  10.     do {
  11.         //cout <<fabs(funkcja(s))<<endl;
  12.     i++;
  13.     s = (a+b) / 2;
  14.  
  15.     if(abs(funkcja(s)) < epsilon)
  16.                         break;
  17.  
  18.     if( funkcja(a) * funkcja(s) < 0 ) {
  19.         b = s;
  20.     } else {
  21.         a = s;
  22.     }
  23.  
  24.     //cout << fabs( f(s) )<<endl;
  25.  
  26.     //cout <<fabs(funkcja(s))<<endl;
  27.     } while( (b-a ) >= epsilon);
  28.  
  29.  
  30.     cout << "X = "          << s<<endl;
  31.     cout << "Dokladnosc = " << epsilon<<endl;
  32.     cout << "kroki = " << i<<endl;
  33. }