Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- float d,a,b,fa,fb,fx, x, selected_number;
- float Bisection(float a, float b){
- int step_nr = 0;
- do{
- step_nr++;
- x = a + b;
- x = x / 2;
- fa = a * a * a - a - 2;
- fb = b * b * b - b - 2;
- fx = x * x * x - x - 2;
- cout << "Krok nr "<< step_nr<<": " << a << " " << b << " " << fa << " " << fb << " " << x << " " << fx << endl;
- if(fa >= 0 && fx >= 0 || fa < 0 && fx < 0){
- a = x;
- b = b;
- }else{
- a = a;
- b = x;
- }
- }while(fx > 0.1 || fx < -0.1);
- }
- int main()
- {
- a = 0;
- b = 2;
- x = Bisection(a,b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment