Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- double func(double x)
- {
- return (-x*x + 6 * x + 5);
- }
- double c;
- void bisection(double a, double b,double e)
- {
- c = a; int i = 0;
- while (abs(b - a) >= e)
- {
- cout << "Iteration #" << i << endl;
- c = (a + b) / 2;
- if (func(c) > func(a)) {
- cout << "Midpoint = " << c << endl;
- cout << "f(" << c << ")=" << func(c) << endl;
- a = c;
- }
- else {
- cout << "Midpoint = " << c << endl;
- cout << "f(" << c << ")=" << func(c) << endl;
- b = c;
- }
- i++;
- }
- }
- int main()
- {
- double a, b, e;
- a = 0;
- b = 5;
- cout << "a = " << a << endl;
- cout << "b = " << b << endl;
- cout << "Enter e:";
- cin >> e;
- bisection(a, b,e);
- cout << "\n";
- cout << "Point of maximum is = " << c << endl;
- cout << "Extr is = " << func(c) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement