poly.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2017, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 #ifndef O2SCL_POLY_H
24 #define O2SCL_POLY_H
25 
26 /** \file poly.h
27  \brief Classes for solving polynomials
28 
29  \warning
30  One must be careful about using pow() in functions using
31  complex<double> since pow(((complex<double>)0.0),3.0) returns
32  (nan,nan). Instead, we should use pow(((complex<double>)0.0),3)
33  which takes an integer for the second argument. The sqrt()
34  function, always succeeds i.e. sqrt(((complex<double>)0.0))=0.0
35 
36  \future The quartics are tested only for a4=1, which should
37  probably be generalized.
38 */
39 
40 #include <iostream>
41 #include <complex>
42 #include <gsl/gsl_math.h>
43 #include <gsl/gsl_complex_math.h>
44 #include <gsl/gsl_complex.h>
45 #include <gsl/gsl_poly.h>
46 #include <o2scl/constants.h>
47 #include <o2scl/err_hnd.h>
48 
49 #ifndef DOXYGEN_NO_O2NS
50 namespace o2scl {
51 #endif
52 
53  /** \brief Solve a quadratic polynomial with real coefficients and
54  real roots [abstract base]
55  */
57  public:
58 
59  virtual ~quadratic_real() {}
60 
61  /** \brief Solves the polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$
62  giving the two solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$ .
63  */
64  virtual int solve_r(const double a2, const double b2, const double c2,
65  double &x1, double &x2)=0;
66 
67  /// Return a string denoting the type ("quadratic_real")
68  const char *type() { return "quadratic_real"; }
69  };
70 
71  /** \brief Solve a quadratic polynomial with real coefficients and
72  complex roots [abstract base]
73  */
75 
76  public:
77 
78  virtual ~quadratic_real_coeff() {}
79 
80  /** \brief Solves the polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$
81  giving the two solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$ .
82  */
83  virtual int solve_r(const double a2, const double b2, const double c2,
84  double &x1, double &x2);
85 
86  /** \brief Solves the polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$
87  giving the two complex solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$
88  */
89  virtual int solve_rc(const double a2, const double b2, const double c2,
90  std::complex<double> &x1,
91  std::complex<double> &x2)=0;
92 
93  /// Return a string denoting the type ("quadratic_real_coeff")
94  const char *type() { return "quadratic_real_coeff"; }
95  };
96 
97  /** \brief Solve a quadratic polynomial with complex coefficients and
98  complex roots [abstract base]
99  */
101  public:
102 
103  virtual ~quadratic_complex() {}
104 
105  /** \brief Solves the polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$
106  giving the two solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$ .
107  */
108  virtual int solve_r(const double a2, const double b2, const double c2,
109  double &x1, double &x2);
110 
111  /** \brief Solves the polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$
112  giving the two complex solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$
113  */
114  virtual int solve_rc(const double a2, const double b2, const double c2,
115  std::complex<double> &x1, std::complex<double> &x2);
116 
117  /** \brief Solves the complex polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$
118  giving the two complex solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$
119  */
120  virtual int solve_c(const std::complex<double> a2,
121  const std::complex<double> b2,
122  const std::complex<double> c2,
123  std::complex<double> &x1, std::complex<double> &x2)=0;
124 
125  /// Return a string denoting the type ("quadratic_complex")
126  const char *type() { return "quadratic_complex"; }
127  };
128 
129  /** \brief Solve a cubic polynomial with real coefficients and real roots
130  [abstract base]
131  */
132  class cubic_real {
133  public:
134 
135  virtual ~cubic_real() {}
136 
137  /** \brief Solves the polynomial
138  \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ giving the three
139  solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ .
140  */
141  virtual int solve_r(const double a3, const double b3, const double c3,
142  const double d3, double &x1, double &x2,
143  double &x3)=0;
144 
145  /// Return a string denoting the type ("cubic_real")
146  const char *type() { return "cubic_real"; }
147  };
148 
149  /** \brief Solve a cubic polynomial with real coefficients and
150  complex roots [abstract base]
151  */
152  class cubic_real_coeff : public cubic_real {
153 
154  public:
155 
156  virtual ~cubic_real_coeff() {}
157 
158  /** \brief Solves the polynomial
159  \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ giving the three
160  solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ .
161  */
162  virtual int solve_r(const double a3, const double b3, const double c3,
163  const double d3, double &x1, double &x2, double &x3);
164 
165  /** \brief Solves the polynomial
166  \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$
167  giving the real solution \f$ x=x_1 \f$ and two complex solutions
168  \f$ x=x_2 \f$ and \f$ x=x_3 \f$ .
169  */
170  virtual int solve_rc(const double a3, const double b3, const double c3,
171  const double d3, double &x1, std::complex<double> &x2,
172  std::complex<double> &x3)=0;
173 
174  /// Return a string denoting the type ("cubic_real_coeff")
175  const char *type() { return "cubic_real_coeff"; }
176  };
177 
178  /** \brief Solve a cubic polynomial with complex coefficients and
179  complex roots [abstract base]
180  */
182 
183  public:
184 
185  virtual ~cubic_complex() {}
186 
187  /** \brief Solves the polynomial
188  \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ giving the three
189  solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ .
190  */
191  virtual int solve_r(const double a3, const double b3, const double c3,
192  const double d3, double &x1, double &x2, double &x3);
193 
194  /** \brief Solves the polynomial
195  \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ giving the real
196  solution \f$ x=x_1 \f$ and two complex solutions
197  \f$ x=x_2 \f$ and \f$ x=x_3 \f$ .
198  */
199  virtual int solve_rc(const double a3, const double b3, const double c3,
200  const double d3, double &x1, std::complex<double> &x2,
201  std::complex<double> &x3);
202 
203  /** \brief Solves the complex polynomial
204  \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$
205  giving the three complex solutions \f$ x=x_1 \f$ ,
206  \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ .
207  */
208  virtual int solve_c(const std::complex<double> a3,
209  const std::complex<double> b3,
210  const std::complex<double> c3,
211  const std::complex<double> d3,
212  std::complex<double> &x1, std::complex<double> &x2,
213  std::complex<double> &x3)=0;
214 
215  /// Return a string denoting the type ("cubic_complex")
216  const char *type() { return "cubic_complex"; }
217  };
218 
219  /** \brief Solve a quartic polynomial with real coefficients and
220  real roots [abstract base]
221  */
222  class quartic_real {
223 
224  public:
225 
226  virtual ~quartic_real() {}
227 
228  /** \brief Solves the polynomial
229  \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$
230  giving the four solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ ,
231  \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ .
232  */
233  virtual int solve_r(const double a4, const double b4, const double c4,
234  const double d4, const double e4,
235  double &x1, double &x2,
236  double &x3, double &x4)=0;
237 
238  /// Return a string denoting the type ("quartic_real")
239  const char *type() { return "quartic_real"; }
240  };
241 
242  /** \brief Solve a quartic polynomial with real coefficients and
243  complex roots [abstract base]
244  */
246 
247  public:
248 
249  virtual ~quartic_real_coeff() {}
250 
251  /** \brief Solves the polynomial
252  \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$
253  giving the four solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ ,
254  \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ .
255  */
256  virtual int solve_r(const double a4, const double b4, const double c4,
257  const double d4, const double e4, double &x1,
258  double &x2, double &x3, double &x4);
259 
260  /** \brief Solves the polynomial
261  \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$
262  giving the four complex solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ ,
263  \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ .
264  */
265  virtual int solve_rc(const double a4, const double b4, const double c4,
266  const double d4, const double e4,
267  std::complex<double> &x1, std::complex<double> &x2,
268  std::complex<double> &x3,
269  std::complex<double> &x4)=0;
270 
271  /// Return a string denoting the type ("quartic_real_coeff")
272  const char *type() { return "quartic_real_coeff"; }
273  };
274 
275  /** \brief Solve a quartic polynomial with complex coefficients and
276  complex roots [abstract base]
277  */
279 
280  public:
281 
282  virtual ~quartic_complex() {}
283 
284  /** \brief Solves the polynomial
285  \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$
286  giving the four solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ ,
287  \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ .
288  */
289  virtual int solve_r(const double a4, const double b4, const double c4,
290  const double d4, const double e4, double &x1,
291  double &x2,
292  double &x3, double &x4);
293 
294  /** \brief Solves the polynomial
295  \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$
296  giving the four complex solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ ,
297  \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ .
298  */
299  virtual int solve_rc(const double a4, const double b4, const double c4,
300  const double d4, const double e4,
301  std::complex<double> &x1, std::complex<double> &x2,
302  std::complex<double> &x3, std::complex<double> &x4);
303 
304  /** \brief Solves the complex polynomial
305  \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$
306  giving the four complex solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ ,
307  \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ .
308  */
309  virtual int solve_c(const std::complex<double> a4,
310  const std::complex<double> b4,
311  const std::complex<double> c4,
312  const std::complex<double> d4,
313  const std::complex<double> e4,
314  std::complex<double> &x1,
315  std::complex<double> &x2, std::complex<double> &x3,
316  std::complex<double> &x4)=0;
317 
318  /// Return a string denoting the type ("quartic_complex")
319  const char *type() { return "quartic_complex"; }
320  };
321 
322  /** \brief Solve a general polynomial with real
323  coefficients and complex roots [abstract base]
324  */
326  public cubic_real_coeff, public quartic_real_coeff {
327 
328  public:
329 
330  virtual ~poly_real_coeff() {}
331 
332  /** \brief Solve the n-th order polynomial
333 
334  The coefficients are stored in co[], with the leading coefficient
335  as co[0] and the constant term as co[n]. The roots are returned
336  in ro[0],...,ro[n-1].
337  */
338  virtual int solve_rc(int n, const double co[],
339  std::complex<double> ro[])=0;
340 
341  /// Return a string denoting the type ("poly_real_coeff")
342  const char *type() { return "poly_real_coeff"; }
343  };
344 
345  /** \brief Solve a general polynomial with complex
346  coefficients [abstract base]
347  */
349  public cubic_complex, public quartic_complex {
350 
351  public:
352 
353  virtual ~poly_complex() {}
354 
355  /** \brief Solve the n-th order polynomial
356 
357  The coefficients are stored in co[], with the leading coefficient
358  as co[0] and the constant term as co[n]. The roots are returned
359  in ro[0],...,ro[n-1].
360  */
361  virtual int solve_c(int n, const std::complex<double> co[],
362  std::complex<double> ro[])=0;
363 
364  /// Polish the roots
365  virtual int polish_c(int n, const std::complex<double> co[],
366  std::complex<double> *ro)=0;
367 
368  /// Return a string denoting the type ("poly_complex")
369  const char *type() { return "poly_complex"; }
370  };
371 
372  /** \brief Solve a cubic with real coefficients and complex roots
373  (CERNLIB)
374 
375  \note The function rrteq3() is based on the CERNLIB routine of
376  the same name, but differs slightly. See the documentation of
377  that function for details.
378  */
380 
381  public:
382 
384  eps=1.0e-6;
385  delta=1.0e-15;
386  improve_scale=true;
387  }
388 
389  /// Numerical tolerance (default \f$ 10^{-6} \f$)
390  double eps;
391 
392  /// Numerical tolerance (default \f$ 10^{-15} \f$)
393  double delta;
394 
395  /// Improve algorithm for poorly-scaled roots (default true)
397 
398  virtual ~cubic_real_coeff_cern() {}
399 
400  /** \brief Solves the polynomial
401  \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ giving the real
402  solution \f$ x=x_1 \f$ and two complex solutions
403  \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ .
404  */
405  virtual int solve_rc(const double a3, const double b3, const double c3,
406  const double d3, double &x1,
407  std::complex<double> &x2, std::complex<double> &x3);
408 
409  /** \brief The CERNLIB-like interface
410 
411  This function computes the roots of the cubic equation
412  \f[
413  x^3 + r x^2 + s x + t =0
414  \f]
415  returning the value of the discriminant in \c d and the roots
416  in the array \c x. If the discriminant is negative, then all
417  three real roots are stored in \c x. Otherwise, the real root
418  is stored in <tt>x[0]</tt> and the real and imaginary parts of
419  the complex conjugate roots are stored in <tt>x[1]</tt> and
420  <tt>x[2]</tt>, respectively. This differs from the CERNLIB
421  routine where the results were stored in <tt>x[1]</tt>,
422  <tt>x[2]</tt>, and <tt>x[3]</tt> instead.
423 
424  Another small change is that the discriminant for the
425  resolvent cubic is evaluated slightly differently in order to
426  improve the properties in the case where the roots are not all
427  of order unity. The default CERNLIB behavior can be restored
428  by setting improve_scale to \c false.
429  */
430  virtual int rrteq3(double r, double s, double t, double x[], double &d);
431 
432  /// Return a string denoting the type ("cubic_real_coeff_cern")
433  const char *type() { return "cubic_real_coeff_cern"; }
434  };
435 
436  /** \brief Solve a quartic with real coefficients and complex
437  roots (CERNLIB)
438  */
440 
441  public:
442 
443  virtual ~quartic_real_coeff_cern() {}
444 
445  /** \brief Solves the polynomial \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 +
446  d_4 x + e_4= 0 \f$ giving the four complex solutions \f$ x=x_1
447  \f$ , \f$ x=x_2 \f$ , \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ .
448  */
449  virtual int solve_rc(const double a4, const double b4, const double c4,
450  const double d4, const double e4,
451  std::complex<double> &x1, std::complex<double> &x2,
452  std::complex<double> &x3, std::complex<double> &x4);
453 
454  /// The CERNLIB-like interface
455  virtual int rrteq4(double a, double b, double c, double d,
456  std::complex<double> z[], double &dc,
457  int &mt);
458 
459  /// Return a string denoting the type ("quartic_real_coeff_cern")
460  const char *type() { return "quartic_real_coeff_cern"; }
461 
462 #ifndef DOXYGEN_INTERNAL
463 
464  protected:
465 
466  /// The object to solve for the associated cubic
468 
469 #endif
470 
471  };
472 
473  /** \brief Solve a quadratic with real coefficients and complex roots (GSL)
474  */
476 
477  public:
478 
479  virtual ~quadratic_real_coeff_gsl() {}
480 
481  /** \brief Solves the polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$
482  giving the two complex solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$
483  */
484  virtual int solve_rc(const double a2, const double b2, const double c2,
485  std::complex<double> &x1, std::complex<double> &x2);
486 
487  /// Return a string denoting the type ("quadratic_real_coeff_gsl")
488  const char *type() { return "quadratic_real_coeff_gsl"; }
489 
490  };
491 
492  /** \brief Solve a cubic with real coefficients and complex roots (GSL)
493  */
495 
496  public:
497 
498  virtual ~cubic_real_coeff_gsl() {}
499 
500  /** \brief Solves the polynomial
501  \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$
502  giving the real solution \f$ x=x_1 \f$ and two complex solutions
503  \f$ x=x_2 \f$ and \f$ x=x_3 \f$ .
504  */
505  virtual int solve_rc(const double a3, const double b3, const double c3,
506  const double d3, double &x1,
507  std::complex<double> &x2, std::complex<double> &x3);
508 
509  /// Return a string denoting the type ("cubic_real_coeff_gsl")
510  const char *type() { return "cubic_real_coeff_gsl"; }
511 
512  /** \brief An alternative to \c gsl_poly_complex_solve_cubic()
513 
514  This is an alternative to the function
515  <tt>gsl_poly_complex_solve_cubic()</tt> with some small
516  corrections to ensure finite values for some cubics. See
517  <tt>src/other/poly_ts.cpp</tt> for more.
518 
519  \future I think the GSL function is now fixed, so we
520  can fall back to the original GSL function here.
521  */
522  int gsl_poly_complex_solve_cubic2(double a, double b, double c,
523  gsl_complex *z0, gsl_complex *z1,
524  gsl_complex *z2);
525 
526  };
527 
528  /** \brief Solve a quartic with real coefficients and real roots (GSL)
529 
530  This class internally uses the GSL functions to solve the
531  resolvent cubic and associated quadratics, while
532  \ref quartic_real_gsl2 contains explicit code to solve
533  them instead.
534 
535  \future Optimize value of \c cube_root_tol and compare
536  more clearly to \ref o2scl::quartic_real_gsl2
537  */
539 
540  public:
541 
542  quartic_real_gsl() {
543  cube_root_tol=1.0e-7;
544  }
545 
546  virtual ~quartic_real_gsl() {}
547 
548  /** \brief A tolerance for determining the proper cube root
549  (default \f$ 10^{-4} \f$ )
550  */
552 
553  /** \brief Solves the polynomial \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 +
554  d_4 x + e_4= 0 \f$ giving the four real solutions \f$ x=x_1
555  \f$ , \f$ x=x_2 \f$ , \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ .
556  */
557  virtual int solve_r(const double a4, const double b4, const double c4,
558  const double d4, const double e4, double &x1,
559  double &x2, double &x3, double &x4);
560 
561  /// Return a string denoting the type ("quartic_real_gsl")
562  const char *type() { return "quartic_real_gsl"; }
563 
564  };
565 
566  /** \brief Solve a quartic with real coefficients and real roots (GSL)
567 
568  This class directly solves
569  resolvent cubic and associated quadratics without using
570  the GSL functions (as done in \ref quartic_real_gsl).
571 
572  \future Optimize value of \c cube_root_tol and compare
573  more clearly to \ref o2scl::quartic_real_gsl
574  */
576 
577  public:
578 
580  cube_root_tol=1.0e-7;
581  }
582 
583  virtual ~quartic_real_gsl2() {}
584 
585  /** \brief A tolerance for determining the proper cube root
586  (default \f$ 10^{-7} \f$ )
587  */
589 
590  /** \brief Solves the polynomial \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 +
591  d_4 x + e_4= 0 \f$ giving the four real solutions \f$ x=x_1
592  \f$ , \f$ x=x_2 \f$ , \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ .
593  */
594  virtual int solve_r(const double a4, const double b4, const double c4,
595  const double d4, const double e4, double &x1,
596  double &x2,
597  double &x3, double &x4);
598 
599  /// Return a string denoting the type ("quartic_real_gsl2")
600  const char *type() { return "quartic_real_gsl2"; }
601  };
602 
603  /** \brief Solve a general polynomial with real coefficients (GSL)
604  */
606 
607  public:
608 
610 
611  virtual ~poly_real_coeff_gsl();
612 
613  /** \brief Solve a generic polynomial given <tt>n+1</tt> coefficients
614 
615  \note In order to be consistent with the other solve_rc()
616  functions, the ordering of the coefficients is reversed with
617  respect to gsl_poly_complex_solve(). The leading coefficient
618  is stored in <tt>co[0]</tt> and the constant term is stored in
619  <tt>co[n]</tt>.
620  */
621  virtual int solve_rc(int n, const double co[],
622  std::complex<double> ro[]);
623 
624  /** \brief Solve a cubic polynomial with real coefficients
625  */
626  virtual int solve_rc(const double a3, const double b3, const double c3,
627  const double d3, double &x1,
628  std::complex<double> &x2,
629  std::complex<double> &x3);
630 
631  /** \brief Solve a quadratic polynomial with real coefficients
632  */
633  virtual int solve_rc(const double a2, const double b2, const double c2,
634  std::complex<double> &x1,
635  std::complex<double> &x2);
636 
637  /** \brief Solve a quartic polynomial with real coefficients
638  */
639  virtual int solve_rc(const double a4, const double b4, const double c4,
640  const double d4, const double e4,
641  std::complex<double> &x1, std::complex<double> &x2,
642  std::complex<double> &x3, std::complex<double> &x4);
643 
644  /// Return a string denoting the type ("poly_real_coeff_gsl")
645  const char *type() { return "poly_real_coeff_gsl"; }
646 
647  protected:
648 
649 #ifndef DOXYGEN_INTERNAL
650 
651  /// Workspace for quadratic polynomials
652  gsl_poly_complex_workspace *w2;
653 
654  /// Workspace for cubic polynomials
655  gsl_poly_complex_workspace *w3;
656 
657  /// Workspace for quartic polynomials
658  gsl_poly_complex_workspace *w4;
659 
660  /// Workspace for general polynomials
661  gsl_poly_complex_workspace *wgen;
662 
663  /// The size of the workspace \ref wgen
664  int gen_size;
665 
666 #endif
667 
668  };
669 
670  /** \brief Solve a quadratic with complex coefficients and complex roots
671  */
673 
674  public:
675 
676  virtual ~quadratic_complex_std() {}
677 
678  /** \brief Solves the complex polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$
679  giving the two complex solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$
680  */
681  virtual int solve_c(const std::complex<double> a2,
682  const std::complex<double> b2,
683  const std::complex<double> c2,
684  std::complex<double> &x1, std::complex<double> &x2);
685 
686  /// Return a string denoting the type ("quadratic_complex_std")
687  const char *type() { return "quadratic_complex_std"; }
688  };
689 
690  /** \brief Solve a cubic with complex coefficients and complex roots
691  */
693 
694  public:
695 
696  virtual ~cubic_complex_std() {}
697 
698  /** \brief Solves the complex polynomial
699  \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$
700  giving the three complex solutions \f$ x=x_1 \f$ ,
701  \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ .
702  */
703  virtual int solve_c(const std::complex<double> a3,
704  const std::complex<double> b3,
705  const std::complex<double> c3,
706  const std::complex<double> d3,
707  std::complex<double> &x1, std::complex<double> &x2,
708  std::complex<double> &x3);
709 
710  /// Return a string denoting the type ("cubic_complex_std")
711  const char *type() { return "cubic_complex_std"; }
712  };
713 
714  /** \brief Solve a quartic with real coefficients and real roots
715  */
717 
718  public:
719 
721  cube_root_tol=1.0e-6;
722  }
723 
724  virtual ~quartic_real_simple() {}
725 
726  virtual int solve_r(const double a4, const double b4, const double c4,
727  const double d4, const double e4, double &x1,
728  double &x2, double &x3, double &x4);
729 
730  /// Return a string denoting the type ("quartic_real_simple")
731  const char *type() { return "quartic_real_simple"; }
732 
733  /** \brief A tolerance for determining the proper cube root
734  (default \f$ 10^{-6} \f$ )
735  */
737  };
738 
739  /** \brief Solve a quartic with complex coefficients and complex roots
740  */
742 
743  public:
744 
745  virtual ~quartic_complex_simple() {}
746 
747  /** \brief Solves the complex polynomial
748  \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$
749  giving the four complex solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ ,
750  \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ .
751  */
752  virtual int solve_c(const std::complex<double> a4,
753  const std::complex<double> b4,
754  const std::complex<double> c4,
755  const std::complex<double> d4,
756  const std::complex<double> e4,
757  std::complex<double> &x1,
758  std::complex<double> &x2,
759  std::complex<double> &x3,
760  std::complex<double> &x4);
761 
762  /// Return a string denoting the type ("quartic_complex_simple")
763  const char *type() { return "quartic_complex_simple"; }
764 
765 #ifndef DOXYGEN_NO_O2NS
766 
767  protected:
768 
769  /// The object to solve for the associated cubic
771 
772 #endif
773 
774  };
775 
776 #ifndef DOXYGEN_NO_O2NS
777 }
778 #endif
779 
780 #endif
const char * type()
Return a string denoting the type ("cubic_real_coeff_cern")
Definition: poly.h:433
const char * type()
Return a string denoting the type ("quadratic_complex")
Definition: poly.h:126
Solve a quadratic with complex coefficients and complex roots.
Definition: poly.h:672
const char * type()
Return a string denoting the type ("quartic_real")
Definition: poly.h:239
const char * type()
Return a string denoting the type ("quartic_real_gsl")
Definition: poly.h:562
double cube_root_tol
A tolerance for determining the proper cube root (default )
Definition: poly.h:551
Solve a general polynomial with real coefficients (GSL)
Definition: poly.h:605
The main O<span style=&#39;position: relative; top: 0.3em; font-size: 0.8em&#39;>2</span>scl O$_2$scl names...
Definition: anneal.h:42
cubic_real_coeff_cern cub_obj
The object to solve for the associated cubic.
Definition: poly.h:467
const char * type()
Return a string denoting the type ("quartic_real_gsl2")
Definition: poly.h:600
Solve a cubic polynomial with real coefficients and real roots [abstract base].
Definition: poly.h:132
int gen_size
The size of the workspace wgen.
Definition: poly.h:664
const char * type()
Return a string denoting the type ("cubic_complex_std")
Definition: poly.h:711
const char * type()
Return a string denoting the type ("quadratic_real")
Definition: poly.h:68
Solve a quartic with real coefficients and complex roots (CERNLIB)
Definition: poly.h:439
cubic_complex_std cub_obj
The object to solve for the associated cubic.
Definition: poly.h:770
Solve a cubic with real coefficients and complex roots (GSL)
Definition: poly.h:494
const char * type()
Return a string denoting the type ("quartic_complex_simple")
Definition: poly.h:763
const char * type()
Return a string denoting the type ("poly_real_coeff")
Definition: poly.h:342
Solve a cubic with real coefficients and complex roots (CERNLIB)
Definition: poly.h:379
const char * type()
Return a string denoting the type ("cubic_real_coeff_gsl")
Definition: poly.h:510
Solve a quartic with complex coefficients and complex roots.
Definition: poly.h:741
const char * type()
Return a string denoting the type ("poly_complex")
Definition: poly.h:369
Solve a quartic polynomial with real coefficients and real roots [abstract base]. ...
Definition: poly.h:222
Solve a quartic with real coefficients and real roots.
Definition: poly.h:716
Solve a quartic polynomial with complex coefficients and complex roots [abstract base].
Definition: poly.h:278
Solve a general polynomial with complex coefficients [abstract base].
Definition: poly.h:348
const char * type()
Return a string denoting the type ("quadratic_real_coeff_gsl")
Definition: poly.h:488
const char * type()
Return a string denoting the type ("cubic_complex")
Definition: poly.h:216
const char * type()
Return a string denoting the type ("quartic_real_simple")
Definition: poly.h:731
const char * type()
Return a string denoting the type ("poly_real_coeff_gsl")
Definition: poly.h:645
Solve a quadratic polynomial with real coefficients and real roots [abstract base].
Definition: poly.h:56
static const double x3[11]
Definition: inte_qng_gsl.h:94
gsl_poly_complex_workspace * w4
Workspace for quartic polynomials.
Definition: poly.h:658
double cube_root_tol
A tolerance for determining the proper cube root (default )
Definition: poly.h:736
Solve a cubic polynomial with complex coefficients and complex roots [abstract base].
Definition: poly.h:181
const char * type()
Return a string denoting the type ("quartic_real_coeff")
Definition: poly.h:272
const char * type()
Return a string denoting the type ("quartic_real_coeff_cern")
Definition: poly.h:460
const char * type()
Return a string denoting the type ("cubic_real_coeff")
Definition: poly.h:175
const char * type()
Return a string denoting the type ("quadratic_real_coeff")
Definition: poly.h:94
gsl_poly_complex_workspace * wgen
Workspace for general polynomials.
Definition: poly.h:661
gsl_poly_complex_workspace * w2
Workspace for quadratic polynomials.
Definition: poly.h:652
bool improve_scale
Improve algorithm for poorly-scaled roots (default true)
Definition: poly.h:396
const char * type()
Return a string denoting the type ("quartic_complex")
Definition: poly.h:319
virtual int solve_r(const double a2, const double b2, const double c2, double &x1, double &x2)=0
Solves the polynomial giving the two solutions and .
Solve a quartic with real coefficients and real roots (GSL)
Definition: poly.h:538
double eps
Numerical tolerance (default )
Definition: poly.h:390
Solve a quartic polynomial with real coefficients and complex roots [abstract base].
Definition: poly.h:245
gsl_poly_complex_workspace * w3
Workspace for cubic polynomials.
Definition: poly.h:655
Solve a cubic polynomial with real coefficients and complex roots [abstract base].
Definition: poly.h:152
static const double x4[22]
Definition: inte_qng_gsl.h:139
Solve a quadratic polynomial with complex coefficients and complex roots [abstract base]...
Definition: poly.h:100
double delta
Numerical tolerance (default )
Definition: poly.h:393
Solve a quadratic polynomial with real coefficients and complex roots [abstract base].
Definition: poly.h:74
Solve a general polynomial with real coefficients and complex roots [abstract base].
Definition: poly.h:325
Solve a quartic with real coefficients and real roots (GSL)
Definition: poly.h:575
Solve a quadratic with real coefficients and complex roots (GSL)
Definition: poly.h:475
static const double x2[5]
Definition: inte_qng_gsl.h:66
static const double x1[5]
Definition: inte_qng_gsl.h:48
const char * type()
Return a string denoting the type ("quadratic_complex_std")
Definition: poly.h:687
Solve a cubic with complex coefficients and complex roots.
Definition: poly.h:692
double cube_root_tol
A tolerance for determining the proper cube root (default )
Definition: poly.h:588
const char * type()
Return a string denoting the type ("cubic_real")
Definition: poly.h:146

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).