Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iomanip>
- #include <iostream>
- using namespace std;
- double f(double x)
- {
- return sqrt((2 - 0.5 * pow(x, 3)) / (3 * x + 1));
- }
- double df(double x)
- {
- return (1.5 * pow(x, 3) - 1.5 * pow(x, 2) - 6) / (2 * sqrt(2 - 0.5 * pow(x, 3)) * pow(3*x + 1, 1.5));
- }
- double g(double x)
- {
- return x - f(x) / df(x);
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- double x;
- double eps;
- cout << "Введите приближенное значение: "; cin >> x;
- cout << "Введите точность (например, 0.000001): "; cin >> eps;
- for(double iter = 1; eps < fabs(f(x)); iter = iter + 1)
- {
- cout<<"Iteration : "<<setprecision(0)<<iter<<endl;
- if(df(x) == 0) // Чёртовский важный момент(!)
- break; // ведь если df(x) == 0, то будет деление на ноль: x - f(x)/df(x)
- cout << "x = " << x << endl;
- cout << "g(x) = " << g(x) << endl;
- cout << "df(x)= " << df(x) << endl;
- cout << "f(x) = " << f(x) << endl;
- x = g(x);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement