gsl_poly.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* poly/gsl_poly.h
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2004, 2007 Brian Gough
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef __GSL_POLY_H__
  20. #define __GSL_POLY_H__
  21. #include <stdlib.h>
  22. #include "gsl_complex.h"
  23. #undef __BEGIN_DECLS
  24. #undef __END_DECLS
  25. #ifdef __cplusplus
  26. # define __BEGIN_DECLS extern "C" {
  27. # define __END_DECLS }
  28. #else
  29. # define __BEGIN_DECLS /* empty */
  30. # define __END_DECLS /* empty */
  31. #endif
  32. __BEGIN_DECLS
  33. /* Evaluate polynomial
  34. *
  35. * c[0] + c[1] x + c[2] x^2 + ... + c[len-1] x^(len-1)
  36. *
  37. * exceptions: none
  38. */
  39. double gsl_poly_eval(const double c[], const int len, const double x);
  40. #ifdef HAVE_INLINE
  41. extern inline
  42. double
  43. gsl_poly_eval(const double c[], const int len, const double x)
  44. {
  45. int i;
  46. double ans = c[len-1];
  47. for(i=len-1; i>0; i--) ans = c[i-1] + x * ans;
  48. return ans;
  49. }
  50. #endif /* HAVE_INLINE */
  51. /* Work with divided-difference polynomials, Abramowitz & Stegun 25.2.26 */
  52. int
  53. gsl_poly_dd_init (double dd[], const double x[], const double y[],
  54. size_t size);
  55. double
  56. gsl_poly_dd_eval (const double dd[], const double xa[], const size_t size, const double x);
  57. #ifdef HAVE_INLINE
  58. extern inline
  59. double
  60. gsl_poly_dd_eval(const double dd[], const double xa[], const size_t size, const double x)
  61. {
  62. size_t i;
  63. double y = dd[size - 1];
  64. for (i = size - 1; i--;) y = dd[i] + (x - xa[i]) * y;
  65. return y;
  66. }
  67. #endif /* HAVE_INLINE */
  68. int
  69. gsl_poly_dd_taylor (double c[], double xp,
  70. const double dd[], const double x[], size_t size,
  71. double w[]);
  72. /* Solve for real or complex roots of the standard quadratic equation,
  73. * returning the number of real roots.
  74. *
  75. * Roots are returned ordered.
  76. */
  77. int gsl_poly_solve_quadratic (double a, double b, double c,
  78. double * x0, double * x1);
  79. int
  80. gsl_poly_complex_solve_quadratic (double a, double b, double c,
  81. gsl_complex * z0, gsl_complex * z1);
  82. /* Solve for real roots of the cubic equation
  83. * x^3 + a x^2 + b x + c = 0, returning the
  84. * number of real roots.
  85. *
  86. * Roots are returned ordered.
  87. */
  88. int gsl_poly_solve_cubic (double a, double b, double c,
  89. double * x0, double * x1, double * x2);
  90. int
  91. gsl_poly_complex_solve_cubic (double a, double b, double c,
  92. gsl_complex * z0, gsl_complex * z1,
  93. gsl_complex * z2);
  94. /* Solve for the complex roots of a general real polynomial */
  95. typedef struct
  96. {
  97. size_t nc ;
  98. double * matrix ;
  99. }
  100. gsl_poly_complex_workspace ;
  101. gsl_poly_complex_workspace * gsl_poly_complex_workspace_alloc (size_t n);
  102. void gsl_poly_complex_workspace_free (gsl_poly_complex_workspace * w);
  103. int
  104. gsl_poly_complex_solve (const double * a, size_t n,
  105. gsl_poly_complex_workspace * w,
  106. gsl_complex_packed_ptr z);
  107. __END_DECLS
  108. #endif /* __GSL_POLY_H__ */