Advertisement
Neveles

Untitled

Apr 12th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. void calcH(double maxh, double hstep, const double delta, double * const*rkf)
  2. {
  3. static uint32_t result_i = 0;
  4. double resultmx = 0;
  5. double resultmy = 0;
  6. double resultmxy = 0;
  7. uint32_t maxCountery = 0;
  8. uint32_t maxCounterx = 0;
  9. uint32_t maxCounterxy = 0;
  10. double h = hstep;
  11. while (h <= maxh)
  12. {
  13. uint32_t counterx = 0;
  14. uint32_t countery = 0;
  15. uint32_t counterxy = 0;
  16. double x1;
  17. double x2;
  18. double x0[2]{ 0, 1 };
  19. uint32_t i = 0;
  20. for (double step = 0; step < 0.41; step += 0.01)
  21. {
  22. x2 = step;
  23. x1 = x2 - 0.01;
  24. rungecutte(step, x0, h);
  25. if (abs(fmax(rkf[i][1], x0[1]) - fmin(rkf[i][1], x0[1])) < delta)
  26. {
  27. ++countery;
  28. }
  29. if (abs(fmax(rkf[i][0], x0[0]) - fmin(rkf[i][0], x0[0])) < delta)
  30. {
  31. ++counterx;
  32. }
  33. if (abs(fmax(rkf[i][0], x0[0]) - fmin(rkf[i][0], x0[0])) < delta &&
  34. abs(fmax(rkf[i][1], x0[1]) - fmin(rkf[i][1], x0[1])) < delta)
  35. {
  36. ++counterxy;
  37. }
  38. ++i;
  39. }
  40. if (maxCounterx <= counterx)
  41. {
  42. resultmx = h;
  43. maxCounterx = counterx;
  44. }
  45. if (maxCountery <= countery)
  46. {
  47. resultmy = h;
  48. maxCountery = countery;
  49. }
  50. if (maxCounterxy <= counterxy)
  51. {
  52. resultmxy = h;
  53. maxCounterxy = counterxy;
  54. }
  55. h += hstep;
  56. }
  57. if (result_i != 0 && std::stoi(deltas[result_i][2].get()[0]) == maxCounterxy
  58. && std::stoi(deltas[result_i][4].get()[0]) == maxCounterx
  59. && std::stoi(deltas[result_i][6].get()[0]) == maxCountery)
  60. {
  61. return;
  62. }
  63. ++result_i;
  64. deltas[result_i][0] = std::to_string(delta);
  65. deltas[result_i][1] = resultmxy;
  66. deltas[result_i][2] = maxCounterxy;
  67. deltas[result_i][3] = resultmx;
  68. deltas[result_i][4] = maxCounterx;
  69. deltas[result_i][5] = resultmy;
  70. deltas[result_i][6] = maxCountery;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement