Advertisement
kasper_k

aip10

Dec 11th, 2021
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double Rech1(double x)
  7. {
  8.     return acos(x) - sqrt(1 - 0.3 * (x * x * x));  // начальная
  9. }
  10. double Rech2(double x)
  11. {
  12.     return ((9 * x * x) / (20 * sqrt(1- 0.3 * (x*x*x))) - 1 / (sqrt(1 - x*x)));           //Производная
  13. }
  14. double opredelit() {//определения грубого значения по условию
  15.     double x0;
  16.     float a = 1, b = 2;
  17.     x0 = a;
  18.     while (Rech1(x0) * Rech2(x0) < 0) {
  19.         if (Rech1(x0) * Rech2(x0) > 0) {
  20.             break;
  21.         }
  22.         else {
  23.             x0 = x0 + 0.01;
  24.         }
  25.     }
  26.     return x0;
  27. }
  28. double newton(double x0) {//метод ньютона
  29.     double  x, amendment;
  30.     double e = 1e-4;
  31.     do
  32.     {
  33.         amendment = -1 * (Rech1(x0) / Rech2(x0));
  34.         x = x0 + amendment;
  35.         if (Rech2(x0) == 0)//проверка на 0 потому что на 0 делить нельзя
  36.             break;
  37.         x0 = x;
  38.  
  39.     } while (abs(Rech1(x0)) > e);
  40.     return x;
  41. }
  42. int main()
  43. {
  44.     setlocale(LC_ALL, "ru");
  45.     double x0 = opredelit();
  46.     //double s = newton(x0);
  47.     cout << x0 << endl;
  48.     cout << "корень уравнения=" << newton(x0) << endl;
  49.     system("pause");
  50.     return 0;
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement