Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 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. double x;
  24. double eps;
  25. cout << "Введите приближенное значение: "; cin >> x;
  26. cout << "Введите точность (например, 0.000001): "; cin >> eps;
  27. for(double iter = 1; eps < fabs(f(x)); iter = iter + 1)
  28. {
  29. cout<<"Iteration : "<<setprecision(0)<<iter<<endl;
  30. if(df(x) == 0) // Чёртовский важный момент(!)
  31. break; // ведь если df(x) == 0, то будет деление на ноль: x - f(x)/df(x)
  32. cout << "x = " << x << endl;
  33. cout << "g(x) = " << g(x) << endl;
  34. cout << "df(x)= " << df(x) << endl;
  35. cout << "f(x) = " << f(x) << endl;
  36. x = g(x);
  37. }
  38.  
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement