00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 2009, Andrew W. Steiner 00005 00006 This file is part of O2scl. 00007 00008 O2scl is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 O2scl is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with O2scl. If not, see <http://www.gnu.org/licenses/>. 00020 00021 ------------------------------------------------------------------- 00022 */ 00023 #ifndef O2SCL_POLY_H 00024 #define O2SCL_POLY_H 00025 00026 /** \file poly.h 00027 \brief Classes for solving polynomials 00028 00029 \warning 00030 We should be careful about using pow() in functions using 00031 complex<double> since pow(((complex<double>)0.0),3.0) returns 00032 (nan,nan). Instead, we should use pow(((complex<double>)0.0),3) 00033 which takes an integer for the second argument. The sqrt() function, 00034 always succeeds i.e. sqrt(((complex<double>)0.0))=0.0 00035 00036 \future The quartics are tested only for a4=1, which should 00037 probably be generalized. 00038 00039 */ 00040 00041 #include <iostream> 00042 #include <complex> 00043 #include <gsl/gsl_math.h> 00044 #include <gsl/gsl_complex_math.h> 00045 #include <gsl/gsl_complex.h> 00046 #include <gsl/gsl_poly.h> 00047 #include <o2scl/constants.h> 00048 #include <o2scl/err_hnd.h> 00049 00050 #ifndef DOXYGENP 00051 namespace o2scl { 00052 #endif 00053 00054 /** 00055 \brief Solve a quadratic polynomial with real coefficients and 00056 real roots [abstract base] 00057 */ 00058 class quadratic_real { 00059 public: 00060 00061 virtual ~quadratic_real() {} 00062 00063 /** \brief Solves the polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$ 00064 giving the two solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$ . 00065 */ 00066 virtual int solve_r(const double a2, const double b2, const double c2, 00067 double &x1, double &x2)=0; 00068 00069 /// Return a string denoting the type ("quadratic_real") 00070 const char *type() { return "quadratic_real"; } 00071 }; 00072 00073 /** 00074 \brief Solve a quadratic polynomial with real coefficients and 00075 complex roots [abstract base] 00076 */ 00077 class quadratic_real_coeff : public quadratic_real { 00078 00079 public: 00080 00081 virtual ~quadratic_real_coeff() {} 00082 00083 /** \brief Solves the polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$ 00084 giving the two solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$ . 00085 */ 00086 virtual int solve_r(const double a2, const double b2, const double c2, 00087 double &x1, double &x2); 00088 00089 /** \brief Solves the polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$ 00090 giving the two complex solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$ 00091 */ 00092 virtual int solve_rc(const double a2, const double b2, const double c2, 00093 std::complex<double> &x1, 00094 std::complex<double> &x2)=0; 00095 00096 /// Return a string denoting the type ("quadratic_real_coeff") 00097 const char *type() { return "quadratic_real_coeff"; } 00098 }; 00099 00100 /** 00101 \brief Solve a quadratic polynomial with complex coefficients and 00102 complex roots [abstract base] 00103 */ 00104 class quadratic_complex : public quadratic_real_coeff { 00105 public: 00106 00107 virtual ~quadratic_complex() {} 00108 00109 /** \brief Solves the polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$ 00110 giving the two solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$ . 00111 */ 00112 virtual int solve_r(const double a2, const double b2, const double c2, 00113 double &x1, double &x2); 00114 00115 /** \brief Solves the polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$ 00116 giving the two complex solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$ 00117 */ 00118 virtual int solve_rc(const double a2, const double b2, const double c2, 00119 std::complex<double> &x1, std::complex<double> &x2); 00120 00121 /** \brief Solves the complex polynomial \f$ a_2 x^2 + b_2 x + c_2 = 0 \f$ 00122 giving the two complex solutions \f$ x=x_1 \f$ and \f$ x=x_2 \f$ 00123 */ 00124 virtual int solve_c(const std::complex<double> a2, 00125 const std::complex<double> b2, 00126 const std::complex<double> c2, 00127 std::complex<double> &x1, 00128 std::complex<double> &x2)=0; 00129 00130 /// Return a string denoting the type ("quadratic_complex") 00131 const char *type() { return "quadratic_complex"; } 00132 }; 00133 00134 /** 00135 \brief Solve a cubic polynomial with real coefficients and real roots 00136 [abstract base] 00137 */ 00138 class cubic_real { 00139 public: 00140 00141 virtual ~cubic_real() {} 00142 00143 /** \brief Solves the polynomial 00144 \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ giving the three 00145 solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ . 00146 */ 00147 virtual int solve_r(const double a3, const double b3, const double c3, 00148 const double d3, double &x1, double &x2, 00149 double &x3)=0; 00150 00151 /// Return a string denoting the type ("cubic_real") 00152 const char *type() { return "cubic_real"; } 00153 }; 00154 00155 /** 00156 \brief Solve a cubic polynomial with real coefficients and 00157 complex roots [abstract base] 00158 */ 00159 class cubic_real_coeff : public cubic_real { 00160 00161 public: 00162 00163 virtual ~cubic_real_coeff() {} 00164 00165 /** \brief Solves the polynomial 00166 \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ giving the three 00167 solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ . 00168 */ 00169 virtual int solve_r(const double a3, const double b3, const double c3, 00170 const double d3, double &x1, double &x2, double &x3); 00171 00172 /** \brief Solves the polynomial 00173 \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ 00174 giving the real solution \f$ x=x_1 \f$ and two complex solutions 00175 \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ . 00176 */ 00177 virtual int solve_rc(const double a3, const double b3, const double c3, 00178 const double d3, double &x1, std::complex<double> &x2, 00179 std::complex<double> &x3)=0; 00180 00181 /// Return a string denoting the type ("cubic_real_coeff") 00182 const char *type() { return "cubic_real_coeff"; } 00183 }; 00184 00185 /** 00186 \brief Solve a cubic polynomial with complex coefficients and 00187 complex roots [abstract base] 00188 */ 00189 class cubic_complex : public cubic_real_coeff { 00190 00191 public: 00192 00193 virtual ~cubic_complex() {} 00194 00195 /** \brief Solves the polynomial 00196 \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ giving the three 00197 solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ . 00198 */ 00199 virtual int solve_r(const double a3, const double b3, const double c3, 00200 const double d3, double &x1, double &x2, double &x3); 00201 00202 /** \brief Solves the polynomial 00203 \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ giving the real 00204 solution \f$ x=x_1 \f$ and two complex solutions 00205 \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ . 00206 */ 00207 virtual int solve_rc(const double a3, const double b3, const double c3, 00208 const double d3, double &x1, std::complex<double> &x2, 00209 std::complex<double> &x3); 00210 00211 /** \brief Solves the complex polynomial 00212 \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ 00213 giving the three complex solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , and 00214 \f$ x=x_3 \f$ . 00215 */ 00216 virtual int solve_c(const std::complex<double> a3, 00217 const std::complex<double> b3, 00218 const std::complex<double> c3, 00219 const std::complex<double> d3, 00220 std::complex<double> &x1, std::complex<double> &x2, 00221 std::complex<double> &x3)=0; 00222 00223 /// Return a string denoting the type ("cubic_complex") 00224 const char *type() { return "cubic_complex"; } 00225 }; 00226 00227 /** 00228 \brief Solve a quartic polynomial with real coefficients and 00229 real roots [abstract base] 00230 */ 00231 class quartic_real { 00232 00233 public: 00234 00235 virtual ~quartic_real() {} 00236 00237 /** \brief Solves the polynomial 00238 \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$ 00239 giving the four solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , 00240 \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ . 00241 */ 00242 virtual int solve_r(const double a4, const double b4, const double c4, 00243 const double d4, const double e4, 00244 double &x1, double &x2, 00245 double &x3, double &x4)=0; 00246 00247 /// Return a string denoting the type ("quartic_real") 00248 const char *type() { return "quartic_real"; } 00249 }; 00250 00251 /** 00252 \brief Solve a quartic polynomial with real coefficients and 00253 complex roots [abstract base] 00254 */ 00255 class quartic_real_coeff : public quartic_real { 00256 00257 public: 00258 00259 virtual ~quartic_real_coeff() {} 00260 00261 /** \brief Solves the polynomial 00262 \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$ 00263 giving the four solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , 00264 \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ . 00265 */ 00266 virtual int solve_r(const double a4, const double b4, const double c4, 00267 const double d4, const double e4, double &x1, 00268 double &x2, double &x3, double &x4); 00269 00270 /** \brief Solves the polynomial 00271 \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$ 00272 giving the four complex solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , 00273 \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ . 00274 */ 00275 virtual int solve_rc(const double a4, const double b4, const double c4, 00276 const double d4, const double e4, 00277 std::complex<double> &x1, std::complex<double> &x2, 00278 std::complex<double> &x3, 00279 std::complex<double> &x4)=0; 00280 00281 /// Return a string denoting the type ("quartic_real_coeff") 00282 const char *type() { return "quartic_real_coeff"; } 00283 }; 00284 00285 /** 00286 \brief Solve a quartic polynomial with complex coefficients and 00287 complex roots [abstract base] 00288 */ 00289 class quartic_complex : public quartic_real_coeff { 00290 00291 public: 00292 00293 virtual ~quartic_complex() {} 00294 00295 /** \brief Solves the polynomial 00296 \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$ 00297 giving the four solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , 00298 \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ . 00299 */ 00300 virtual int solve_r(const double a4, const double b4, const double c4, 00301 const double d4, const double e4, double &x1, 00302 double &x2, 00303 double &x3, double &x4); 00304 00305 /** \brief Solves the polynomial 00306 \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$ 00307 giving the four complex solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , 00308 \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ . 00309 */ 00310 virtual int solve_rc(const double a4, const double b4, const double c4, 00311 const double d4, const double e4, 00312 std::complex<double> &x1, std::complex<double> &x2, 00313 std::complex<double> &x3, std::complex<double> &x4); 00314 00315 /** \brief Solves the complex polynomial 00316 \f$ a_4 x^4 + b_4 x^3 + c_4 x^2 + d_4 x + e_4 = 0 \f$ 00317 giving the four complex solutions \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , 00318 \f$ x=x_3 \f$ , and \f$ x=x_4 \f$ . 00319 */ 00320 virtual int solve_c(const std::complex<double> a4, 00321 const std::complex<double> b4, 00322 const std::complex<double> c4, 00323 const std::complex<double> d4, 00324 const std::complex<double> e4, 00325 std::complex<double> &x1, 00326 std::complex<double> &x2, std::complex<double> &x3, 00327 std::complex<double> &x4)=0; 00328 00329 /// Return a string denoting the type ("quartic_complex") 00330 const char *type() { return "quartic_complex"; } 00331 }; 00332 00333 /** \brief Solve a general polynomial with real 00334 coefficients and complex roots [abstract base] 00335 */ 00336 class poly_real_coeff : public quadratic_real_coeff, 00337 public cubic_real_coeff, public quartic_real_coeff { 00338 00339 public: 00340 00341 virtual ~poly_real_coeff() {} 00342 00343 /** 00344 \brief Solve the n-th order polynomial 00345 00346 The coefficients are stored in co[], with the leading coefficient 00347 as co[0] and the constant term as co[n]. The roots are returned 00348 in ro[0],...,ro[n-1]. 00349 */ 00350 virtual int solve_rc(int n, const double co[], 00351 std::complex<double> ro[])=0; 00352 00353 /// Return a string denoting the type ("poly_real_coeff") 00354 const char *type() { return "poly_real_coeff"; } 00355 }; 00356 00357 /** \brief Solve a general polynomial with complex 00358 coefficients [abstract base] 00359 */ 00360 class poly_complex : public quadratic_complex, 00361 public cubic_complex, public quartic_complex { 00362 00363 public: 00364 00365 virtual ~poly_complex() {} 00366 00367 /** 00368 \brief Solve the n-th order polynomial 00369 00370 The coefficients are stored in co[], with the leading coefficient 00371 as co[0] and the constant term as co[n]. The roots are returned 00372 in ro[0],...,ro[n-1]. 00373 */ 00374 virtual int solve_c(int n, const std::complex<double> co[], 00375 std::complex<double> ro[])=0; 00376 00377 /// Polish the roots 00378 virtual int polish_c(int n, const std::complex<double> co[], 00379 std::complex<double> *ro)=0; 00380 00381 /// Return a string denoting the type ("poly_complex") 00382 const char *type() { return "poly_complex"; } 00383 }; 00384 00385 /** 00386 \brief Solve a cubic with real coefficients and complex roots 00387 (CERNLIB) 00388 00389 This follows the original Fortran code except in the 00390 function rrteq3(), the roots 00391 are returned in x[0], x[1], and x[2] instead of x[1], x[2], and 00392 x[3]. (The arrays y and z were already zero-indexed in the CERN 00393 routine.) Similar to the original, in the case of complex roots, 00394 x[0] is the real root and x[1] and x[2] contain the real and 00395 imaginary parts of the complex roots. 00396 00397 Another small change is that the discriminant for the resolvent 00398 cubic is evaluated slightly differently in order to improve 00399 the properties in the case where the roots are not of order 00400 unity. The default CERNLIB behavior can be restored by 00401 setting improve_scale to \c false. 00402 */ 00403 class cern_cubic_real_coeff : public cubic_real_coeff { 00404 00405 public: 00406 00407 cern_cubic_real_coeff() { 00408 eps=1.0e-6; 00409 delta=1.0e-15; 00410 improve_scale=true; 00411 } 00412 00413 /// Numerical tolerance (default \f$ 10^{-6} \f$) 00414 double eps; 00415 00416 /// Numerical tolerance (default \f$ 10^{-15} \f$) 00417 double delta; 00418 00419 /// Improve algorithm for bad-scaled roots (default true) 00420 bool improve_scale; 00421 00422 virtual ~cern_cubic_real_coeff() {} 00423 00424 /** \brief Solves the polynomial 00425 \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ giving the real 00426 solution \f$ x=x_1 \f$ and two complex solutions 00427 \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ . 00428 */ 00429 virtual int solve_rc(const double a3, const double b3, const double c3, 00430 const double d3, double &x1, 00431 std::complex<double> &x2, std::complex<double> &x3); 00432 00433 /** \brief The original CERNLIB interface 00434 */ 00435 virtual int rrteq3(double r, double s, double t, double x[], double &d); 00436 00437 /// Return a string denoting the type ("cern_cubic_real_coeff") 00438 const char *type() { return "cern_cubic_real_coeff"; } 00439 }; 00440 00441 /** 00442 \brief Solve a quartic with real coefficients and complex roots (CERNLIB) 00443 */ 00444 class cern_quartic_real_coeff : public quartic_real_coeff { 00445 00446 public: 00447 00448 virtual ~cern_quartic_real_coeff() {} 00449 00450 virtual int solve_rc(const double a4, const double b4, const double c4, 00451 const double d4, const double e4, 00452 std::complex<double> &x1, std::complex<double> &x2, 00453 std::complex<double> &x3, std::complex<double> &x4); 00454 00455 /// The original CERNLIB interface 00456 virtual int rrteq4(double a, double b, double c, double d, 00457 std::complex<double> z[], double &dc, 00458 int &mt); 00459 00460 /// Return a string denoting the type ("cern_quartic_real_coeff") 00461 const char *type() { return "cern_quartic_real_coeff"; } 00462 00463 #ifndef DOXYGEN_INTERNAL 00464 00465 protected: 00466 00467 /// The object to solve for the associated cubic 00468 cern_cubic_real_coeff cub_obj; 00469 00470 #endif 00471 00472 }; 00473 00474 /** 00475 \brief Solve a quadratic with real coefficients and complex roots (GSL) 00476 */ 00477 class gsl_quadratic_real_coeff : public quadratic_real_coeff { 00478 00479 public: 00480 00481 virtual ~gsl_quadratic_real_coeff() {} 00482 00483 virtual int solve_rc(const double a2, const double b2, const double c2, 00484 std::complex<double> &x1, std::complex<double> &x2); 00485 00486 /// Return a string denoting the type ("gsl_quadratic_real_coeff") 00487 const char *type() { return "gsl_quadratic_real_coeff"; } 00488 00489 }; 00490 00491 /** 00492 \brief Solve a cubic with real coefficients and complex roots (GSL) 00493 */ 00494 class gsl_cubic_real_coeff : public cubic_real_coeff { 00495 00496 public: 00497 00498 virtual ~gsl_cubic_real_coeff() {} 00499 00500 virtual int solve_rc(const double a3, const double b3, const double c3, 00501 const double d3, double &x1, 00502 std::complex<double> &x2, 00503 std::complex<double> &x3); 00504 00505 /// Return a string denoting the type ("gsl_cubic_real_coeff") 00506 const char *type() { return "gsl_cubic_real_coeff"; } 00507 00508 /** 00509 \brief An alternative to \c gsl_poly_complex_solve_cubic() 00510 00511 This is an alternative to the function 00512 <tt>gsl_poly_complex_solve_cubic()</tt> with some small 00513 corrections to ensure finite values for some cubics. See 00514 <tt>src/other/poly_ts.cpp</tt> for more. 00515 */ 00516 int gsl_poly_complex_solve_cubic2(double a, double b, double c, 00517 gsl_complex *z0, gsl_complex *z1, 00518 gsl_complex *z2); 00519 00520 }; 00521 00522 /** 00523 \brief Solve a quartic with real coefficients and real roots (GSL) 00524 00525 This class internally uses the GSL functions to solve the 00526 resolvent cubic and associated quadratics, while 00527 \ref gsl_quartic_real2 contains explicit code to solve 00528 them instead. 00529 00530 \future Optimize value of \c cube_root_tol and compare 00531 more clearly to \ref gsl_quartic_real2 00532 */ 00533 class gsl_quartic_real : public quartic_real { 00534 00535 public: 00536 00537 gsl_quartic_real() { 00538 cube_root_tol=1.0e-7; 00539 } 00540 00541 virtual ~gsl_quartic_real() {} 00542 00543 /** 00544 \brief A tolerance for determining the proper cube root 00545 (default \f$ 10^{-4} \f$ ) 00546 */ 00547 double cube_root_tol; 00548 00549 virtual int solve_r(const double a4, const double b4, const double c4, 00550 const double d4, const double e4, double &x1, 00551 double &x2, 00552 double &x3, double &x4); 00553 00554 /// Return a string denoting the type ("gsl_quartic_real") 00555 const char *type() { return "gsl_quartic_real"; } 00556 00557 }; 00558 00559 /** 00560 \brief Solve a quartic with real coefficients and real roots (GSL) 00561 00562 This class directly solves 00563 resolvent cubic and associated quadratics without using 00564 the GSL functions (as done in \ref gsl_quartic_real). 00565 00566 \future Optimize value of \c cube_root_tol and compare 00567 more clearly to \ref gsl_quartic_real 00568 */ 00569 class gsl_quartic_real2 : public quartic_real { 00570 00571 public: 00572 00573 gsl_quartic_real2() { 00574 cube_root_tol=1.0e-7; 00575 } 00576 00577 virtual ~gsl_quartic_real2() {} 00578 00579 /** 00580 \brief A tolerance for determining the proper cube root 00581 (default \f$ 10^{-7} \f$ ) 00582 */ 00583 double cube_root_tol; 00584 00585 virtual int solve_r(const double a4, const double b4, const double c4, 00586 const double d4, const double e4, double &x1, 00587 double &x2, 00588 double &x3, double &x4); 00589 00590 /// Return a string denoting the type ("gsl_quartic_real2") 00591 const char *type() { return "gsl_quartic_real2"; } 00592 }; 00593 00594 /** 00595 \brief Solve a general polynomial with real coefficients (GSL) 00596 */ 00597 class gsl_poly_real_coeff : public poly_real_coeff { 00598 00599 public: 00600 00601 gsl_poly_real_coeff(); 00602 00603 virtual ~gsl_poly_real_coeff(); 00604 00605 virtual int solve_rc(int n, const double co[], 00606 std::complex<double> ro[]); 00607 00608 virtual int solve_rc(const double a3, const double b3, const double c3, 00609 const double d3, double &x1, 00610 std::complex<double> &x2, 00611 std::complex<double> &x3); 00612 00613 virtual int solve_rc(const double a2, const double b2, const double c2, 00614 std::complex<double> &x1, 00615 std::complex<double> &x2); 00616 00617 virtual int solve_rc(const double a4, const double b4, const double c4, 00618 const double d4, const double e4, 00619 std::complex<double> &x1, std::complex<double> &x2, 00620 std::complex<double> &x3, std::complex<double> &x4); 00621 00622 /// Return a string denoting the type ("gsl_poly_real_coeff") 00623 const char *type() { return "gsl_poly_real_coeff"; } 00624 00625 protected: 00626 00627 #ifndef DOXYGEN_INTERNAL 00628 00629 /// Workspace for quadratic polynomials 00630 gsl_poly_complex_workspace *w2; 00631 00632 /// Workspace for cubic polynomials 00633 gsl_poly_complex_workspace *w3; 00634 00635 /// Workspace for quartic polynomials 00636 gsl_poly_complex_workspace *w4; 00637 00638 /// Workspace for general polynomials 00639 gsl_poly_complex_workspace *wgen; 00640 00641 /// The size of the workspace \ref wgen 00642 int gen_size; 00643 00644 #endif 00645 00646 }; 00647 00648 /** 00649 \brief Solve a quadratic with complex coefficients and complex roots 00650 */ 00651 class quadratic_std_complex : public quadratic_complex { 00652 00653 public: 00654 00655 virtual ~quadratic_std_complex() {} 00656 00657 virtual int solve_c(const std::complex<double> a2, 00658 const std::complex<double> b2, 00659 const std::complex<double> c2, 00660 std::complex<double> &x1, std::complex<double> &x2); 00661 00662 /// Return a string denoting the type ("quadratic_std_complex") 00663 const char *type() { return "quadratic_std_complex"; } 00664 }; 00665 00666 /** 00667 \brief Solve a cubic with complex coefficients and complex roots 00668 */ 00669 class cubic_std_complex : public cubic_complex { 00670 00671 public: 00672 00673 virtual ~cubic_std_complex() {} 00674 00675 virtual int solve_c(const std::complex<double> a3, 00676 const std::complex<double> b3, 00677 const std::complex<double> c3, 00678 const std::complex<double> d3, 00679 std::complex<double> &x1, std::complex<double> &x2, 00680 std::complex<double> &x3); 00681 00682 /// Return a string denoting the type ("cubic_std_complex") 00683 const char *type() { return "cubic_std_complex"; } 00684 }; 00685 00686 /** 00687 \brief Solve a quartic with real coefficients and real roots 00688 */ 00689 class simple_quartic_real : public quartic_real { 00690 00691 public: 00692 00693 simple_quartic_real() { 00694 cube_root_tol=1.0e-6; 00695 } 00696 00697 virtual ~simple_quartic_real() {} 00698 00699 virtual int solve_r(const double a4, const double b4, const double c4, 00700 const double d4, const double e4, double &x1, 00701 double &x2, double &x3, double &x4); 00702 00703 /// Return a string denoting the type ("simple_quartic_real") 00704 const char *type() { return "simple_quartic_real"; } 00705 00706 /** 00707 \brief A tolerance for determining the proper cube root 00708 (default \f$ 10^{-6} \f$ ) 00709 */ 00710 double cube_root_tol; 00711 }; 00712 00713 /** 00714 \brief Solve a quartic with complex coefficients and complex roots 00715 */ 00716 class simple_quartic_complex : public quartic_complex { 00717 00718 public: 00719 00720 virtual ~simple_quartic_complex() {} 00721 00722 virtual int solve_c(const std::complex<double> a4, 00723 const std::complex<double> b4, 00724 const std::complex<double> c4, 00725 const std::complex<double> d4, 00726 const std::complex<double> e4, 00727 std::complex<double> &x1, 00728 std::complex<double> &x2, std::complex<double> &x3, 00729 std::complex<double> &x4); 00730 00731 /// Return a string denoting the type ("simple_quartic_complex") 00732 const char *type() { return "simple_quartic_complex"; } 00733 00734 #ifndef DOXYGENP 00735 00736 protected: 00737 00738 /// The object to solve for the associated cubic 00739 cubic_std_complex cub_obj; 00740 00741 #endif 00742 00743 }; 00744 00745 #ifndef DOXYGENP 00746 } 00747 #endif 00748 00749 #endif
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page