spherical_harmonic.qbk 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. [section:sph_harm Spherical Harmonics]
  2. [h4 Synopsis]
  3. ``
  4. #include <boost/math/special_functions/spherical_harmonic.hpp>
  5. ``
  6. namespace boost{ namespace math{
  7. template <class T1, class T2>
  8. std::complex<``__sf_result``> spherical_harmonic(unsigned n, int m, T1 theta, T2 phi);
  9. template <class T1, class T2, class ``__Policy``>
  10. std::complex<``__sf_result``> spherical_harmonic(unsigned n, int m, T1 theta, T2 phi, const ``__Policy``&);
  11. template <class T1, class T2>
  12. ``__sf_result`` spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi);
  13. template <class T1, class T2, class ``__Policy``>
  14. ``__sf_result`` spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi, const ``__Policy``&);
  15. template <class T1, class T2>
  16. ``__sf_result`` spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi);
  17. template <class T1, class T2, class ``__Policy``>
  18. ``__sf_result`` spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi, const ``__Policy``&);
  19. }} // namespaces
  20. [h4 Description]
  21. The return type of these functions is computed using the __arg_promotion_rules
  22. when T1 and T2 are different types.
  23. [optional_policy]
  24. template <class T1, class T2>
  25. std::complex<``__sf_result``> spherical_harmonic(unsigned n, int m, T1 theta, T2 phi);
  26. template <class T1, class T2, class ``__Policy``>
  27. std::complex<``__sf_result``> spherical_harmonic(unsigned n, int m, T1 theta, T2 phi, const ``__Policy``&);
  28. Returns the value of the Spherical Harmonic Y[sub n][super m](theta, phi):
  29. [equation spherical_0]
  30. The spherical harmonics Y[sub n][super m](theta, phi) are the angular
  31. portion of the solution to Laplace's equation in spherical coordinates
  32. where azimuthal symmetry is not present.
  33. [caution Care must be taken in correctly identifying the arguments to this
  34. function: [theta] is taken as the polar (colatitudinal) coordinate
  35. with [theta] in \[0, [pi]\], and [phi]as the azimuthal (longitudinal)
  36. coordinate with [phi]in \[0,2[pi]). This is the convention used in Physics,
  37. and matches the definition used by
  38. [@http://documents.wolfram.com/mathematica/functions/SphericalHarmonicY
  39. Mathematica in the function SpericalHarmonicY],
  40. but is opposite to the usual mathematical conventions.
  41. Some other sources include an additional Condon-Shortley phase term of
  42. (-1)[super m] in the definition of this function: note however that our
  43. definition of the associated Legendre polynomial already includes this term.
  44. This implementation returns zero for m > n
  45. For [theta] outside \[0, [pi]\] and [phi] outside \[0, 2[pi]\] this
  46. implementation follows the convention used by Mathematica:
  47. the function is periodic with period [pi] in [theta] and 2[pi] in
  48. [phi]. Please note that this is not the behaviour one would get
  49. from a casual application of the function's definition. Cautious users
  50. should keep [theta] and [phi] to the range \[0, [pi]\] and
  51. \[0, 2[pi]\] respectively.
  52. See: [@http://mathworld.wolfram.com/SphericalHarmonic.html
  53. Weisstein, Eric W. "Spherical Harmonic."
  54. From MathWorld--A Wolfram Web Resource]. ]
  55. template <class T1, class T2>
  56. ``__sf_result`` spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi);
  57. template <class T1, class T2, class ``__Policy``>
  58. ``__sf_result`` spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi, const ``__Policy``&);
  59. Returns the real part of Y[sub n][super m](theta, phi):
  60. [equation spherical_1]
  61. template <class T1, class T2>
  62. ``__sf_result`` spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi);
  63. template <class T1, class T2, class ``__Policy``>
  64. ``__sf_result`` spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi, const ``__Policy``&);
  65. Returns the imaginary part of Y[sub n][super m](theta, phi):
  66. [equation spherical_2]
  67. [h4 Accuracy]
  68. The following table shows peak errors for various domains of input arguments.
  69. Note that only results for the widest floating point type on the system are
  70. given as narrower types have __zero_error. Peak errors are the same
  71. for both the real and imaginary parts, as the error is dominated by
  72. calculation of the associated Legendre polynomials: especially near the
  73. roots of the associated Legendre function.
  74. All values are in units of epsilon.
  75. [table_spherical_harmonic_r]
  76. [table_spherical_harmonic_i]
  77. Note that the worst errors occur when the degree increases, values greater than
  78. ~120 are very unlikely to produce sensible results, especially
  79. when the order is also large. Further the relative errors
  80. are likely to grow arbitrarily large when the function is very close to a root.
  81. [h4 Testing]
  82. A mixture of spot tests of values calculated using functions.wolfram.com,
  83. and randomly generated test data are
  84. used: the test data was computed using
  85. [@http://shoup.net/ntl/doc/RR.txt NTL::RR] at 1000-bit precision.
  86. [h4 Implementation]
  87. These functions are implemented fairly naively using the formulae
  88. given above. Some extra care is taken to prevent roundoff error
  89. when converting from polar coordinates (so for example the
  90. ['1-x[super 2]] term used by the associated Legendre functions is calculated
  91. without roundoff error using ['x = cos(theta)], and
  92. ['1-x[super 2] = sin[super 2](theta)]). The limiting factor in the error
  93. rates for these functions is the need to calculate values near the roots
  94. of the associated Legendre functions.
  95. [endsect] [/section:beta_function The Beta Function]
  96. [/
  97. Copyright 2006 John Maddock and Paul A. Bristow.
  98. Distributed under the Boost Software License, Version 1.0.
  99. (See accompanying file LICENSE_1_0.txt or copy at
  100. http://www.boost.org/LICENSE_1_0.txt).
  101. ]