Guest User

Untitled

a guest
Feb 17th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. float  d,a,b,fa,fb,fx, x, selected_number;
  6.  
  7.  
  8. float Bisection(float a, float b){
  9.     int step_nr = 0;
  10.     do{
  11.         step_nr++;
  12.         x = a + b;
  13.         x = x / 2;
  14.         fa = a * a * a - a - 2;
  15.         fb = b * b * b - b - 2;
  16.         fx = x * x * x - x - 2;
  17.         cout << "Krok nr "<< step_nr<<": " << a  << " " << b  << " " << fa << " " << fb << " " << x << " " << fx << endl;
  18.         if(fa >= 0 && fx >= 0 || fa < 0 && fx < 0){
  19.             a = x;
  20.             b = b;
  21.         }else{
  22.             a = a;
  23.             b = x;
  24.         }
  25.     }while(fx > 0.1 || fx < -0.1);
  26.  
  27. }
  28.  
  29.  
  30. int main()
  31. {
  32.     a = 0;
  33.     b = 2;
  34.     x = Bisection(a,b);
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment