Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <cmath>
  2. #include <iomanip>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. double f(double x)
  7. {
  8. return sqrt((2 - 0.5 * pow(x, 3)) / (3 * x + 1));
  9. }
  10.  
  11. double df(double x)
  12. {
  13. 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));
  14. }
  15.  
  16. double g(double x)
  17. {
  18. return x - f(x) / df(x);
  19. }
  20.  
  21. int main()
  22. {
  23. setlocale(LC_ALL, "rus");
  24. double x;
  25. double eps;
  26. cout << "Введите приближенное значение: "; cin >> x;
  27. cout << "Введите точность (например, 0.000001): "; cin >> eps;
  28. for(double iter = 1; eps < fabs(f(x)); iter = iter + 1)
  29. {
  30. cout<<"Iteration : "<<setprecision(0)<<iter<<endl;
  31. if(df(x) == 0) // Чёртовский важный момент(!)
  32. break; // ведь если df(x) == 0, то будет деление на ноль: x - f(x)/df(x)
  33. cout << "x = " << x << endl;
  34. cout << "g(x) = " << g(x) << endl;
  35. cout << "df(x)= " << df(x) << endl;
  36. cout << "f(x) = " << f(x) << endl;
  37. x = g(x);
  38. }
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement