Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Метод дихотомии */
- #include <iostream>
- #include <cmath>
- using namespace std;
- const double PI = 3.14;
- const double eps = 0.001;
- double findRoot(double a, double b, double eps);
- int main()
- {
- double a; double b;
- cout << "a = ";
- cin >> a;
- cout << "b = ";
- cin >> b;
- cout << endl;
- cout << "Результат: " << "\n";
- cout << "x = " << findRoot(a, b, eps);
- cout << endl;
- return 0;
- }
- double f(double x) {
- return (1.0 / x) - PI * cos(PI * x);
- }
- double findRoot(double a, double b, double eps) {
- double c;
- while (abs((b - a) / 2.0) > eps) {
- c = (a + b) / 2.0;
- if ((f(a) * f(c)) < 0) {
- b = c;
- } else {
- a = c;
- }
- }
- return c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement