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 function 00390 rrteq3(), the roots are returned in x[0], x[1], and x[2] instead 00391 of x[1], x[2], and x[3]. (The arrays y and z were already 00392 zero-indexed in the CERN routine.) Similar to the original, in 00393 the case of complex roots, x[0] is the real root and x[1] and 00394 x[2] contain the real and imaginary parts of the complex roots. 00395 00396 Another small change is that the discriminant for the resolvent 00397 cubic is evaluated slightly differently in order to improve the 00398 properties in the case where the roots are not of order unity. 00399 The default CERNLIB behavior can be restored by setting 00400 improve_scale to \c false. 00401 */ 00402 class cern_cubic_real_coeff : public cubic_real_coeff { 00403 00404 public: 00405 00406 cern_cubic_real_coeff() { 00407 eps=1.0e-6; 00408 delta=1.0e-15; 00409 improve_scale=true; 00410 } 00411 00412 /// Numerical tolerance (default \f$ 10^{-6} \f$) 00413 double eps; 00414 00415 /// Numerical tolerance (default \f$ 10^{-15} \f$) 00416 double delta; 00417 00418 /// Improve algorithm for bad-scaled roots (default true) 00419 bool improve_scale; 00420 00421 virtual ~cern_cubic_real_coeff() {} 00422 00423 /** \brief Solves the polynomial 00424 \f$ a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \f$ giving the real 00425 solution \f$ x=x_1 \f$ and two complex solutions 00426 \f$ x=x_1 \f$ , \f$ x=x_2 \f$ , and \f$ x=x_3 \f$ . 00427 */ 00428 virtual int solve_rc(const double a3, const double b3, const double c3, 00429 const double d3, double &x1, 00430 std::complex<double> &x2, std::complex<double> &x3); 00431 00432 /** \brief The CERNLIB-like interface 00433 */ 00434 virtual int rrteq3(double r, double s, double t, double x[], double &d); 00435 00436 /// Return a string denoting the type ("cern_cubic_real_coeff") 00437 const char *type() { return "cern_cubic_real_coeff"; } 00438 }; 00439 00440 /** 00441 \brief Solve a quartic with real coefficients and complex roots (CERNLIB) 00442 */ 00443 class cern_quartic_real_coeff : public quartic_real_coeff { 00444 00445 public: 00446 00447 virtual ~cern_quartic_real_coeff() {} 00448 00449 virtual int solve_rc(const double a4, const double b4, const double c4, 00450 const double d4, const double e4, 00451 std::complex<double> &x1, std::complex<double> &x2, 00452 std::complex<double> &x3, std::complex<double> &x4); 00453 00454 /// The CERNLIB-like interface 00455 virtual int rrteq4(double a, double b, double c, double d, 00456 std::complex<double> z[], double &dc, 00457 int &mt); 00458 00459 /// Return a string denoting the type ("cern_quartic_real_coeff") 00460 const char *type() { return "cern_quartic_real_coeff"; } 00461 00462 #ifndef DOXYGEN_INTERNAL 00463 00464 protected: 00465 00466 /// The object to solve for the associated cubic 00467 cern_cubic_real_coeff cub_obj; 00468 00469 #endif 00470 00471 }; 00472 00473 /** 00474 \brief Solve a quadratic with real coefficients and complex roots (GSL) 00475 */ 00476 class gsl_quadratic_real_coeff : public quadratic_real_coeff { 00477 00478 public: 00479 00480 virtual ~gsl_quadratic_real_coeff() {} 00481 00482 virtual int solve_rc(const double a2, const double b2, const double c2, 00483 std::complex<double> &x1, std::complex<double> &x2); 00484 00485 /// Return a string denoting the type ("gsl_quadratic_real_coeff") 00486 const char *type() { return "gsl_quadratic_real_coeff"; } 00487 00488 }; 00489 00490 /** 00491 \brief Solve a cubic with real coefficients and complex roots (GSL) 00492 */ 00493 class gsl_cubic_real_coeff : public cubic_real_coeff { 00494 00495 public: 00496 00497 virtual ~gsl_cubic_real_coeff() {} 00498 00499 virtual int solve_rc(const double a3, const double b3, const double c3, 00500 const double d3, double &x1, 00501 std::complex<double> &x2, 00502 std::complex<double> &x3); 00503 00504 /// Return a string denoting the type ("gsl_cubic_real_coeff") 00505 const char *type() { return "gsl_cubic_real_coeff"; } 00506 00507 /** 00508 \brief An alternative to \c gsl_poly_complex_solve_cubic() 00509 00510 This is an alternative to the function 00511 <tt>gsl_poly_complex_solve_cubic()</tt> with some small 00512 corrections to ensure finite values for some cubics. See 00513 <tt>src/other/poly_ts.cpp</tt> for more. 00514 */ 00515 int gsl_poly_complex_solve_cubic2(double a, double b, double c, 00516 gsl_complex *z0, gsl_complex *z1, 00517 gsl_complex *z2); 00518 00519 }; 00520 00521 /** 00522 \brief Solve a quartic with real coefficients and real roots (GSL) 00523 00524 This class internally uses the GSL functions to solve the 00525 resolvent cubic and associated quadratics, while 00526 \ref gsl_quartic_real2 contains explicit code to solve 00527 them instead. 00528 00529 \future Optimize value of \c cube_root_tol and compare 00530 more clearly to \ref gsl_quartic_real2 00531 */ 00532 class gsl_quartic_real : public quartic_real { 00533 00534 public: 00535 00536 gsl_quartic_real() { 00537 cube_root_tol=1.0e-7; 00538 } 00539 00540 virtual ~gsl_quartic_real() {} 00541 00542 /** 00543 \brief A tolerance for determining the proper cube root 00544 (default \f$ 10^{-4} \f$ ) 00545 */ 00546 double cube_root_tol; 00547 00548 virtual int solve_r(const double a4, const double b4, const double c4, 00549 const double d4, const double e4, double &x1, 00550 double &x2, 00551 double &x3, double &x4); 00552 00553 /// Return a string denoting the type ("gsl_quartic_real") 00554 const char *type() { return "gsl_quartic_real"; } 00555 00556 }; 00557 00558 /** 00559 \brief Solve a quartic with real coefficients and real roots (GSL) 00560 00561 This class directly solves 00562 resolvent cubic and associated quadratics without using 00563 the GSL functions (as done in \ref gsl_quartic_real). 00564 00565 \future Optimize value of \c cube_root_tol and compare 00566 more clearly to \ref gsl_quartic_real 00567 */ 00568 class gsl_quartic_real2 : public quartic_real { 00569 00570 public: 00571 00572 gsl_quartic_real2() { 00573 cube_root_tol=1.0e-7; 00574 } 00575 00576 virtual ~gsl_quartic_real2() {} 00577 00578 /** 00579 \brief A tolerance for determining the proper cube root 00580 (default \f$ 10^{-7} \f$ ) 00581 */ 00582 double cube_root_tol; 00583 00584 virtual int solve_r(const double a4, const double b4, const double c4, 00585 const double d4, const double e4, double &x1, 00586 double &x2, 00587 double &x3, double &x4); 00588 00589 /// Return a string denoting the type ("gsl_quartic_real2") 00590 const char *type() { return "gsl_quartic_real2"; } 00591 }; 00592 00593 /** 00594 \brief Solve a general polynomial with real coefficients (GSL) 00595 */ 00596 class gsl_poly_real_coeff : public poly_real_coeff { 00597 00598 public: 00599 00600 gsl_poly_real_coeff(); 00601 00602 virtual ~gsl_poly_real_coeff(); 00603 00604 virtual int solve_rc(int n, const double co[], 00605 std::complex<double> ro[]); 00606 00607 virtual int solve_rc(const double a3, const double b3, const double c3, 00608 const double d3, double &x1, 00609 std::complex<double> &x2, 00610 std::complex<double> &x3); 00611 00612 virtual int solve_rc(const double a2, const double b2, const double c2, 00613 std::complex<double> &x1, 00614 std::complex<double> &x2); 00615 00616 virtual int solve_rc(const double a4, const double b4, const double c4, 00617 const double d4, const double e4, 00618 std::complex<double> &x1, std::complex<double> &x2, 00619 std::complex<double> &x3, std::complex<double> &x4); 00620 00621 /// Return a string denoting the type ("gsl_poly_real_coeff") 00622 const char *type() { return "gsl_poly_real_coeff"; } 00623 00624 protected: 00625 00626 #ifndef DOXYGEN_INTERNAL 00627 00628 /// Workspace for quadratic polynomials 00629 gsl_poly_complex_workspace *w2; 00630 00631 /// Workspace for cubic polynomials 00632 gsl_poly_complex_workspace *w3; 00633 00634 /// Workspace for quartic polynomials 00635 gsl_poly_complex_workspace *w4; 00636 00637 /// Workspace for general polynomials 00638 gsl_poly_complex_workspace *wgen; 00639 00640 /// The size of the workspace \ref wgen 00641 int gen_size; 00642 00643 #endif 00644 00645 }; 00646 00647 /** 00648 \brief Solve a quadratic with complex coefficients and complex roots 00649 */ 00650 class quadratic_std_complex : public quadratic_complex { 00651 00652 public: 00653 00654 virtual ~quadratic_std_complex() {} 00655 00656 virtual int solve_c(const std::complex<double> a2, 00657 const std::complex<double> b2, 00658 const std::complex<double> c2, 00659 std::complex<double> &x1, std::complex<double> &x2); 00660 00661 /// Return a string denoting the type ("quadratic_std_complex") 00662 const char *type() { return "quadratic_std_complex"; } 00663 }; 00664 00665 /** 00666 \brief Solve a cubic with complex coefficients and complex roots 00667 */ 00668 class cubic_std_complex : public cubic_complex { 00669 00670 public: 00671 00672 virtual ~cubic_std_complex() {} 00673 00674 virtual int solve_c(const std::complex<double> a3, 00675 const std::complex<double> b3, 00676 const std::complex<double> c3, 00677 const std::complex<double> d3, 00678 std::complex<double> &x1, std::complex<double> &x2, 00679 std::complex<double> &x3); 00680 00681 /// Return a string denoting the type ("cubic_std_complex") 00682 const char *type() { return "cubic_std_complex"; } 00683 }; 00684 00685 /** 00686 \brief Solve a quartic with real coefficients and real roots 00687 */ 00688 class simple_quartic_real : public quartic_real { 00689 00690 public: 00691 00692 simple_quartic_real() { 00693 cube_root_tol=1.0e-6; 00694 } 00695 00696 virtual ~simple_quartic_real() {} 00697 00698 virtual int solve_r(const double a4, const double b4, const double c4, 00699 const double d4, const double e4, double &x1, 00700 double &x2, double &x3, double &x4); 00701 00702 /// Return a string denoting the type ("simple_quartic_real") 00703 const char *type() { return "simple_quartic_real"; } 00704 00705 /** 00706 \brief A tolerance for determining the proper cube root 00707 (default \f$ 10^{-6} \f$ ) 00708 */ 00709 double cube_root_tol; 00710 }; 00711 00712 /** 00713 \brief Solve a quartic with complex coefficients and complex roots 00714 */ 00715 class simple_quartic_complex : public quartic_complex { 00716 00717 public: 00718 00719 virtual ~simple_quartic_complex() {} 00720 00721 virtual int solve_c(const std::complex<double> a4, 00722 const std::complex<double> b4, 00723 const std::complex<double> c4, 00724 const std::complex<double> d4, 00725 const std::complex<double> e4, 00726 std::complex<double> &x1, 00727 std::complex<double> &x2, std::complex<double> &x3, 00728 std::complex<double> &x4); 00729 00730 /// Return a string denoting the type ("simple_quartic_complex") 00731 const char *type() { return "simple_quartic_complex"; } 00732 00733 #ifndef DOXYGENP 00734 00735 protected: 00736 00737 /// The object to solve for the associated cubic 00738 cubic_std_complex cub_obj; 00739 00740 #endif 00741 00742 }; 00743 00744 #ifndef DOXYGENP 00745 } 00746 #endif 00747 00748 #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