Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iostream>
- #include <cmath>
- using namespace std;
- double function(double a, double b, double x) {
- double res;
- res = 1 / x - log(a*x + b);
- return res;
- }
- double HalfDivisionMethod(double xl, double xr, double eps, double a, double b) {
- double x = (xl + xr) / 2;
- if (abs(function(a, b, x)) < eps) return x;
- double fl = function(a, b, xl);
- double fx = function(a, b, x);
- if (fl*fx < 0) {
- cout <<"x = "<< x <<endl;
- cout << "fl = " << fl << endl;
- cout << "fx = " << fx << endl;
- cout << "xl = " << xl << endl;
- cout << "xr = " << xr << endl;
- cout << "Идем влево" << endl<<endl;
- HalfDivisionMethod(xl, x, eps, a, b);
- }
- else {
- cout << "x = " << x << endl;
- cout << "fl = " << fl << endl;
- cout << "fx = " << fx << endl;
- cout << "xl = " << xl << endl;
- cout << "xr = " << xr << endl;
- cout << "Идем вправо" << endl << endl;
- HalfDivisionMethod(x, xr, eps, a, b);
- }
- }
- int main()
- {
- setlocale(LC_ALL, "Rus");
- cout << "Hello, world!";
- cout << HalfDivisionMethod(0.1, 1, 0.00001, 3, 5);
- int a;
- cin >> a;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement