Advertisement
Pagoniusz

Untitled

Apr 21st, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. void newton_rapshon(vector<double>& results, vector<int>& iterations, double a, double b)
  2. {
  3.     double beg_point = (a + b) / 2;
  4.     double x1 = beg_point - 1, f0 = function(beg_point), x0 = beg_point, f1;
  5.     int iteration_count = 0;
  6.     while ((fabs(x1 - x0) > EPSILON) && (fabs(f0) > EPSILON))
  7.     {
  8.         f1 = derivative_of_function(x0);
  9.         x1 = x0;
  10.         x0 = x0 - f0 / f1;
  11.         f0 = function(x0);
  12.         iteration_count++;
  13.         if (iteration_count > NMAX)
  14.             break;
  15.     }
  16.     if (x0>a && x0<b)
  17.     {
  18.         results.push_back(x0);
  19.         iterations.push_back(iteration_count);
  20.     }
  21. }
  22.  
  23. a = A_POINT, b = A_POINT + 0.5;
  24.     while (b != B_POINT)
  25.     {
  26.         newton_rapshon(results, iterations, a, b);
  27.         a += 0.5;
  28.         b += 0.5;
  29.     }
  30.  
  31.  
  32. Metoda Stycznych
  33. Wyniki:
  34. x1 = -9.424777960769379300 Iteracje: 3
  35. x2 = -6.283185307179576500 Iteracje: 2
  36. x3 = -3.141592653589793100 Iteracje: 3
  37. x4 = -0.000000000000000000 Iteracje: 3
  38. x5 = 0.000000000000000000 Iteracje: 3
  39. x6 = 3.141592653589793100 Iteracje: 3
  40. x7 = 6.283185307179576500 Iteracje: 2
  41. x8 = 9.424777960769379300 Iteracje: 3
  42. Suma iteracji = 22
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement