Last active
January 5, 2022 21:09
-
-
Save Yegorsh/e190c787d7c222fec153faac8b59e8ea to your computer and use it in GitHub Desktop.
Revisions
-
Yegorsh revised this gist
Jan 5, 2022 . No changes.There are no files selected for viewing
-
Yegorsh revised this gist
Dec 21, 2021 . No changes.There are no files selected for viewing
-
Yegorsh created this gist
Dec 21, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ #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; }