| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> |
| <title>Spherical Harmonics</title> |
| <link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> |
| <meta name="generator" content="DocBook XSL Stylesheets V1.74.0"> |
| <link rel="home" href="../../../index.html" title="Math Toolkit"> |
| <link rel="up" href="../sf_poly.html" title="Polynomials"> |
| <link rel="prev" href="hermite.html" title="Hermite Polynomials"> |
| <link rel="next" href="../bessel.html" title="Bessel Functions"> |
| </head> |
| <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| <table cellpadding="2" width="100%"><tr> |
| <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> |
| <td align="center"><a href="../../../../../../../../index.html">Home</a></td> |
| <td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> |
| <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> |
| <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> |
| <td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> |
| </tr></table> |
| <hr> |
| <div class="spirit-nav"> |
| <a accesskey="p" href="hermite.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_poly.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../bessel.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> |
| </div> |
| <div class="section" lang="en"> |
| <div class="titlepage"><div><div><h4 class="title"> |
| <a name="math_toolkit.special.sf_poly.sph_harm"></a><a class="link" href="sph_harm.html" title="Spherical Harmonics"> Spherical Harmonics</a> |
| </h4></div></div></div> |
| <a name="math_toolkit.special.sf_poly.sph_harm.synopsis"></a><h5> |
| <a name="id1119782"></a> |
| <a class="link" href="sph_harm.html#math_toolkit.special.sf_poly.sph_harm.synopsis">Synopsis</a> |
| </h5> |
| <p> |
| |
| </p> |
| <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">special_functions</span><span class="special">/</span><span class="identifier">spheric_harmonic</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> |
| </pre> |
| <p> |
| </p> |
| <pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span> |
| |
| <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">></span> |
| <span class="identifier">std</span><span class="special">::</span><span class="identifier">complex</span><span class="special"><</span><a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a><span class="special">></span> <span class="identifier">spherical_harmonic</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">phi</span><span class="special">);</span> |
| |
| <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Policies">Policy</a><span class="special">></span> |
| <span class="identifier">std</span><span class="special">::</span><span class="identifier">complex</span><span class="special"><</span><a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a><span class="special">></span> <span class="identifier">spherical_harmonic</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">phi</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Policies">Policy</a><span class="special">&);</span> |
| |
| <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">></span> |
| <a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">spherical_harmonic_r</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">phi</span><span class="special">);</span> |
| |
| <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Policies">Policy</a><span class="special">></span> |
| <a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">spherical_harmonic_r</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">phi</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Policies">Policy</a><span class="special">&);</span> |
| |
| <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">></span> |
| <a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">spherical_harmonic_i</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">phi</span><span class="special">);</span> |
| |
| <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Policies">Policy</a><span class="special">></span> |
| <a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">spherical_harmonic_i</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">phi</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Policies">Policy</a><span class="special">&);</span> |
| |
| <span class="special">}}</span> <span class="comment">// namespaces |
| </span></pre> |
| <a name="math_toolkit.special.sf_poly.sph_harm.description"></a><h5> |
| <a name="id1120607"></a> |
| <a class="link" href="sph_harm.html#math_toolkit.special.sf_poly.sph_harm.description">Description</a> |
| </h5> |
| <p> |
| The return type of these functions is computed using the <a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>result |
| type calculation rules</em></span></a> when T1 and T2 are different types. |
| </p> |
| <p> |
| </p> |
| <p> |
| The final <a class="link" href="../../policy.html" title="Policies">Policy</a> argument |
| is optional and can be used to control the behaviour of the function: |
| how it handles errors, what level of precision to use etc. Refer to the |
| <a class="link" href="../../policy.html" title="Policies">policy documentation for more details</a>. |
| </p> |
| <p> |
| </p> |
| <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">></span> |
| <span class="identifier">std</span><span class="special">::</span><span class="identifier">complex</span><span class="special"><</span><a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a><span class="special">></span> <span class="identifier">spherical_harmonic</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">phi</span><span class="special">);</span> |
| |
| <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Policies">Policy</a><span class="special">></span> |
| <span class="identifier">std</span><span class="special">::</span><span class="identifier">complex</span><span class="special"><</span><a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a><span class="special">></span> <span class="identifier">spherical_harmonic</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">phi</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Policies">Policy</a><span class="special">&);</span> |
| </pre> |
| <p> |
| Returns the value of the Spherical Harmonic Y<sub>n</sub><sup>m</sup>(theta, phi): |
| </p> |
| <p> |
| <span class="inlinemediaobject"><img src="../../../../equations/spherical_0.png"></span> |
| </p> |
| <p> |
| The spherical harmonics Y<sub>n</sub><sup>m</sup>(theta, phi) are the angular portion of the |
| solution to Laplace's equation in spherical coordinates where azimuthal |
| symmetry is not present. |
| </p> |
| <div class="caution"><table border="0" summary="Caution"> |
| <tr> |
| <td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../../doc/src/images/caution.png"></td> |
| <th align="left">Caution</th> |
| </tr> |
| <tr><td align="left" valign="top"> |
| <p> |
| Care must be taken in correctly identifying the arguments to this function: |
| θ ​ is taken as the polar (colatitudinal) coordinate with θ ​ in [0, π], and φ ​ as |
| the azimuthal (longitudinal) coordinate with φ ​ in [0,2π). This is the convention |
| used in Physics, and matches the definition used by <a href="http://documents.wolfram.com/mathematica/functions/SphericalHarmonicY" target="_top">Mathematica |
| in the function SpericalHarmonicY</a>, but is opposite to the usual |
| mathematical conventions. |
| </p> |
| <p> |
| Some other sources include an additional Condon-Shortley phase term of |
| (-1)<sup>m</sup> in the definition of this function: note however that our definition |
| of the associated Legendre polynomial already includes this term. |
| </p> |
| <p> |
| This implementation returns zero for m > n |
| </p> |
| <p> |
| For θ ​ outside [0, π] and φ ​ outside [0, 2π] this implementation follows the |
| convention used by Mathematica: the function is periodic with period |
| π ​ in θ ​ and 2π ​ in φ. Please note that this is not the behaviour one would get |
| from a casual application of the function's definition. Cautious users |
| should keep θ ​ and φ ​ to the range [0, π] and [0, 2π] respectively. |
| </p> |
| <p> |
| See: <a href="http://mathworld.wolfram.com/SphericalHarmonic.html" target="_top">Weisstein, |
| Eric W. "Spherical Harmonic." From MathWorld--A Wolfram Web |
| Resource</a>. |
| </p> |
| </td></tr> |
| </table></div> |
| <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">></span> |
| <a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">spherical_harmonic_r</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">phi</span><span class="special">);</span> |
| |
| <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Policies">Policy</a><span class="special">></span> |
| <a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">spherical_harmonic_r</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">phi</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Policies">Policy</a><span class="special">&);</span> |
| </pre> |
| <p> |
| Returns the real part of Y<sub>n</sub><sup>m</sup>(theta, phi): |
| </p> |
| <p> |
| <span class="inlinemediaobject"><img src="../../../../equations/spherical_1.png"></span> |
| </p> |
| <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">></span> |
| <a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">spherical_harmonic_i</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">phi</span><span class="special">);</span> |
| |
| <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Policies">Policy</a><span class="special">></span> |
| <a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">spherical_harmonic_i</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">phi</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Policies">Policy</a><span class="special">&);</span> |
| </pre> |
| <p> |
| Returns the imaginary part of Y<sub>n</sub><sup>m</sup>(theta, phi): |
| </p> |
| <p> |
| <span class="inlinemediaobject"><img src="../../../../equations/spherical_2.png"></span> |
| </p> |
| <a name="math_toolkit.special.sf_poly.sph_harm.accuracy"></a><h5> |
| <a name="id1122231"></a> |
| <a class="link" href="sph_harm.html#math_toolkit.special.sf_poly.sph_harm.accuracy">Accuracy</a> |
| </h5> |
| <p> |
| The following table shows peak errors for various domains of input arguments. |
| Note that only results for the widest floating point type on the system |
| are given as narrower types have <a class="link" href="../../backgrounders/relative_error.html#zero_error">effectively |
| zero error</a>. Peak errors are the same for both the real and imaginary |
| parts, as the error is dominated by calculation of the associated Legendre |
| polynomials: especially near the roots of the associated Legendre function. |
| </p> |
| <p> |
| All values are in units of epsilon. |
| </p> |
| <div class="table"> |
| <a name="math_toolkit.special.sf_poly.sph_harm.peak_errors_in_the_sperical_harmonic_functions"></a><p class="title"><b>Table 35. Peak Errors In the Sperical Harmonic Functions</b></p> |
| <div class="table-contents"><table class="table" summary="Peak Errors In the Sperical Harmonic Functions"> |
| <colgroup> |
| <col> |
| <col> |
| <col> |
| </colgroup> |
| <thead><tr> |
| <th> |
| <p> |
| Significand Size |
| </p> |
| </th> |
| <th> |
| <p> |
| Platform and Compiler |
| </p> |
| </th> |
| <th> |
| <p> |
| Errors in range |
| </p> |
| <p> |
| 0 < l < 20 |
| </p> |
| </th> |
| </tr></thead> |
| <tbody> |
| <tr> |
| <td> |
| <p> |
| 53 |
| </p> |
| </td> |
| <td> |
| <p> |
| Win32, Visual C++ 8 |
| </p> |
| </td> |
| <td> |
| <p> |
| Peak=2x10<sup>4</sup> Mean=700 |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| 64 |
| </p> |
| </td> |
| <td> |
| <p> |
| SUSE Linux IA32, g++ 4.1 |
| </p> |
| </td> |
| <td> |
| <p> |
| Peak=2900 Mean=100 |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| 64 |
| </p> |
| </td> |
| <td> |
| <p> |
| Red Hat Linux IA64, g++ 3.4.4 |
| </p> |
| </td> |
| <td> |
| <p> |
| Peak=2900 Mean=100 |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| 113 |
| </p> |
| </td> |
| <td> |
| <p> |
| HPUX IA64, aCC A.06.06 |
| </p> |
| </td> |
| <td> |
| <p> |
| Peak=6700 Mean=230 |
| </p> |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| </div> |
| <br class="table-break"><p> |
| Note that the worst errors occur when the degree increases, values greater |
| than ~120 are very unlikely to produce sensible results, especially when |
| the order is also large. Further the relative errors are likely to grow |
| arbitrarily large when the function is very close to a root. |
| </p> |
| <a name="math_toolkit.special.sf_poly.sph_harm.testing"></a><h5> |
| <a name="id1122423"></a> |
| <a class="link" href="sph_harm.html#math_toolkit.special.sf_poly.sph_harm.testing">Testing</a> |
| </h5> |
| <p> |
| A mixture of spot tests of values calculated using functions.wolfram.com, |
| and randomly generated test data are used: the test data was computed using |
| <a href="http://shoup.net/ntl/doc/RR.txt" target="_top">NTL::RR</a> at 1000-bit |
| precision. |
| </p> |
| <a name="math_toolkit.special.sf_poly.sph_harm.implementation"></a><h5> |
| <a name="id1122444"></a> |
| <a class="link" href="sph_harm.html#math_toolkit.special.sf_poly.sph_harm.implementation">Implementation</a> |
| </h5> |
| <p> |
| These functions are implemented fairly naively using the formulae given |
| above. Some extra care is taken to prevent roundoff error when converting |
| from polar coordinates (so for example the <span class="emphasis"><em>1-x<sup>2</sup></em></span> term |
| used by the associated Legendre functions is calculated without roundoff |
| error using <span class="emphasis"><em>x = cos(theta)</em></span>, and <span class="emphasis"><em>1-x<sup>2</sup> = sin<sup>2</sup>(theta)</em></span>). |
| The limiting factor in the error rates for these functions is the need |
| to calculate values near the roots of the associated Legendre functions. |
| </p> |
| </div> |
| <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> |
| <td align="left"></td> |
| <td align="right"><div class="copyright-footer">Copyright © 2006 , 2007, 2008, 2009, 2010 John Maddock, Paul A. Bristow, |
| Hubert Holin, Xiaogang Zhang, Bruno Lalande, Johan Råde, Gautam Sewani and |
| Thijs van den Berg<p> |
| Distributed under the Boost Software License, Version 1.0. (See accompanying |
| file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) |
| </p> |
| </div></td> |
| </tr></table> |
| <hr> |
| <div class="spirit-nav"> |
| <a accesskey="p" href="hermite.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_poly.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../bessel.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> |
| </div> |
| </body> |
| </html> |