Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. template <typename T> int sgn(T val) {
  2. return (T(0) < val) - (val < T(0));
  3. }
  4.  
  5. std::vector<std::pair<double, double>> find_intervals(double from, double to, double step) {
  6. std::vector<std::pair<double, double>> roots;
  7. std::pair<double, double> p;
  8. double x1, x2;
  9. x1 = from;
  10. x2 = x1 + step;
  11. while (x2 < to) {
  12. if (sgn(f(x1)) != sgn(f(x2))) {
  13. p.first = x1;
  14. p.second = x2;
  15. roots.emplace_back(p);
  16. std::cout << "found interval from " << x1 << " to " << x2 << std::endl;
  17. }
  18. x1 = x2;
  19. x2 += step;
  20. }
  21.  
  22. return roots;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement