gsl_chebyshev.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* cheb/gsl_chebyshev.h
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
  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_CHEBYSHEV_H__
  20. #define __GSL_CHEBYSHEV_H__
  21. #include "gsl_math.h"
  22. #include "gsl_mode.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. /* data for a Chebyshev series over a given interval */
  34. struct gsl_cheb_series_struct {
  35. double * c; /* coefficients */
  36. size_t order; /* order of expansion */
  37. double a; /* lower interval point */
  38. double b; /* upper interval point */
  39. /* The following exists (mostly) for the benefit
  40. * of the implementation. It is an effective single
  41. * precision order, for use in single precision
  42. * evaluation. Users can use it if they like, but
  43. * only they know how to calculate it, since it is
  44. * specific to the approximated function. By default,
  45. * order_sp = order.
  46. * It is used explicitly only by the gsl_cheb_eval_mode
  47. * functions, which are not meant for casual use.
  48. */
  49. size_t order_sp;
  50. /* Additional elements not used by specfunc */
  51. double * f; /* function evaluated at chebyschev points */
  52. };
  53. typedef struct gsl_cheb_series_struct gsl_cheb_series;
  54. /* Calculate a Chebyshev series of specified order over
  55. * a specified interval, for a given function.
  56. * Return 0 on failure.
  57. */
  58. gsl_cheb_series * gsl_cheb_alloc(const size_t order);
  59. /* Free a Chebyshev series previously calculated with gsl_cheb_alloc().
  60. */
  61. void gsl_cheb_free(gsl_cheb_series * cs);
  62. /* Calculate a Chebyshev series using the storage provided.
  63. * Uses the interval (a,b) and the order with which it
  64. * was initially created.
  65. *
  66. */
  67. int gsl_cheb_init(gsl_cheb_series * cs, const gsl_function * func,
  68. const double a, const double b);
  69. /* Evaluate a Chebyshev series at a given point.
  70. * No errors can occur for a struct obtained from gsl_cheb_new().
  71. */
  72. double gsl_cheb_eval(const gsl_cheb_series * cs, const double x);
  73. int gsl_cheb_eval_err(const gsl_cheb_series * cs, const double x,
  74. double * result, double * abserr);
  75. /* Evaluate a Chebyshev series at a given point, to (at most) the given order.
  76. * No errors can occur for a struct obtained from gsl_cheb_new().
  77. */
  78. double gsl_cheb_eval_n(const gsl_cheb_series * cs, const size_t order,
  79. const double x);
  80. int gsl_cheb_eval_n_err(const gsl_cheb_series * cs, const size_t order,
  81. const double x, double * result, double * abserr);
  82. /* Evaluate a Chebyshev series at a given point, using the default
  83. * order for double precision mode(s) and the single precision
  84. * order for other modes.
  85. * No errors can occur for a struct obtained from gsl_cheb_new().
  86. */
  87. double gsl_cheb_eval_mode(const gsl_cheb_series * cs, const double x, gsl_mode_t mode);
  88. int gsl_cheb_eval_mode_e(const gsl_cheb_series * cs, const double x, gsl_mode_t mode, double * result, double * abserr);
  89. /* Compute the derivative of a Chebyshev series.
  90. */
  91. int gsl_cheb_calc_deriv(gsl_cheb_series * deriv, const gsl_cheb_series * cs);
  92. /* Compute the integral of a Chebyshev series. The
  93. * integral is fixed by the condition that it equals zero at
  94. * the left end-point, ie it is precisely
  95. * Integrate[cs(t; a,b), {t, a, x}]
  96. */
  97. int gsl_cheb_calc_integ(gsl_cheb_series * integ, const gsl_cheb_series * cs);
  98. __END_DECLS
  99. #endif /* __GSL_CHEBYSHEV_H__ */