Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename T> int sgn(T val) {
- return (T(0) < val) - (val < T(0));
- }
- std::vector<std::pair<double, double>> find_intervals(double from, double to, double step) {
- std::vector<std::pair<double, double>> roots;
- std::pair<double, double> p;
- double x1, x2;
- x1 = from;
- x2 = x1 + step;
- while (x2 < to) {
- if (sgn(f(x1)) != sgn(f(x2))) {
- p.first = x1;
- p.second = x2;
- roots.emplace_back(p);
- std::cout << "found interval from " << x1 << " to " << x2 << std::endl;
- }
- x1 = x2;
- x2 += step;
- }
- return roots;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement