Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <array>
- #include <complex>
- #include <utility>
- #include <vector>
- #include <math.h>
- #include <limits>
- namespace Equations {
- template<typename t>
- std::pair<bool, std::vector<std::complex<t> > > quadratic(std::array< std::complex<t>, 3> arr)
- {
- std::pair<bool, std::vector<std::complex<t> > > p;
- if (std::norm(arr[2]) < std::numeric_limits<t>::epsilon() &&
- std::norm(arr[1]) < std::numeric_limits<t>::epsilon() &&
- std::norm(arr[0]) < std::numeric_limits<t>::epsilon()) {
- p.first = false;
- } else if (std::norm(arr[2]) < std::numeric_limits<t>::epsilon() &&
- std::norm(arr[1]) < std::numeric_limits<t>::epsilon() &&
- std::norm(arr[0]) >= std::numeric_limits<t>::epsilon()) {
- p.first = true;
- } else if (std::norm(arr[2]) < std::numeric_limits<t>::epsilon()) {
- std::vector<std::complex<t> > v = {-arr[1]/arr[2]};
- p.first = true;
- p.second = v;
- } else {
- std::vector<std::complex<t> > v;
- std::complex<t> d = arr[1] * arr[1] - std::complex<t>(4) * arr[2] * arr[0];
- v.push_back((-arr[1] - std::sqrt(d))/(std::complex<t>(2) * arr[2]));
- v.push_back((-arr[1] + std::sqrt(d))/(std::complex<t>(2) * arr[2]));
- p.first = true;
- p.second = v;
- }
- return p;
- }
- }
- // std::norm(arr[0] < std::norm_limits<t>::eplsilon())
- /*если все нули - беск много а =0 - линейное
- а =0 и б=0 с != 0 , то нет реш иначе (b^2 +- sqrt(d)) / 2a */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement