Last active
January 5, 2022 21:09
-
-
Save Yegorsh/e190c787d7c222fec153faac8b59e8ea 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 foo(double x){ | |
| return log(x) - 5; | |
| } | |
| double SecantMethod(double x0, double x1, const double epsilon){ | |
| double x2; | |
| do { | |
| x2 = x0 - ((foo(x0) * (x1 - x0)) / (foo(x1) - foo(x0))); | |
| x0 = x1; | |
| x1 = x2; | |
| } while (fabs(x1 - x0) > epsilon); | |
| return x2; | |
| } | |
| int main(){ | |
| double eps = 0.0000001; | |
| double x0, x1; | |
| cout << "x0 = "; | |
| cin >> x0; | |
| cout << "x1 = "; | |
| cin >> x1; | |
| if (foo(x0) * foo(x1)>0){ | |
| cout << "F(x0)*F(x1)>0!"; | |
| exit(0); | |
| } | |
| cout << SecantMethod(x0, x1, eps); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment