Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- double f(double);
- double Sec(double, double, double);
- double f(double x){
- return log(x) - 5 * cos(x);
- }
- double Sec(double a, double b, double epsilon){
- double x1 = a;
- double x2 = b;
- double fb = f(b);
- while (abs(f(x2)) > epsilon){
- double mpoint = x2 - (x2 - x1) * fb / (fb - f(x1));
- x1 = x2;
- x2 = mpoint;
- fb = f(x2);
- }
- return x2;
- }
- int main(){
- cout << "Your function: ln(x) - 5cos(x) " << endl;
- cout << "a = 1, b = 8" << endl << endl;
- double a = 1;
- double b = a + 1;
- double eps = 0.00001;
- for (int i = 1; i <= 8; i++) {
- double y = Sec(a, b, eps);
- if (y >= a && y < b)
- cout << "x = " << y << endl;
- a++;
- b++;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement