27 int countroots = gsl_poly_solve_quadratic(
c(2),
c(1),
c(0), &x0, &x1);
29 if (countroots == 0) {
30 return std::vector<double>{};
31 }
else if (countroots == 1) {
32 return std::vector{ x0 };
34 return std::vector{ x0, x1 };
43 using CVector = std::vector<std::complex<double>>;
45 gsl_poly_complex_solve_quadratic(
c(2),
c(1),
c(0), &z0, &z1);
46 return CVector{ { GSL_REAL(z0), GSL_IMAG(z0) },
47 { GSL_REAL(z1), GSL_IMAG(z1) } };
57 auto showResults = [](
const QPolynom &p) {
58 std::cout << p << std::endl;
60 auto roots = p.real_roots();
62 std::cout <<
"no real roots" << std::endl;
63 auto croots = p.complex_roots();
64 for (
const auto &z : croots) {
65 std::cout << z << std::endl;
68 std::cout <<
"real roots" << std::endl;
69 for (
const auto &x : roots) {
70 std::cout << x << std::endl;
79 std::cout <<
"-------------------" << std::endl;
void ex1()
cppx4 Beispiel Berechnung von Nullstellen eines quadratischen Polynoms
The Polynom class Darstellung von Polynomen.
T c(size_t idx) const
c lese Koeffizienten
The QPolynom class Nullstellen eines quadratischen Polynoms mit reellen Koeffizienten.
auto real_roots() const
real_roots berechne reelle Nullstellen
auto complex_roots() const
complex_roots berechne komplexe Nullstellen