Last active
January 5, 2022 21:09
-
-
Save Yegorsh/76d5c6bafe51a3ce6c0adf0044ea306d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <math.h> | |
| using namespace std; | |
| double f(double x){ | |
| return log(x) - 5; | |
| } | |
| double rightDerivative (double x, double h){ | |
| double rightDer = (f(x+h) - f(x))/h; | |
| return rightDer; | |
| } | |
| double NewtonsMethod(double x0, double epsilon){ | |
| double x1; | |
| for (int j=0; ; j++){ | |
| x1 = x0 - ( f(x0) / rightDerivative(x0, 0.000001) ); | |
| if (fabs(x1 - x0) > epsilon){ | |
| x0 = x1; | |
| } | |
| else { | |
| return x1; | |
| } | |
| } | |
| } | |
| int main(){ | |
| double x0; | |
| double eps = 0.000001; | |
| cout << "Нулевое приближение: "; | |
| cin >> x0; | |
| double result = NewtonsMethod(x0, eps); | |
| cout << result; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment