hernlund
02-23-2003, 12:54 PM
To Spherical People,
In many calculations it is necessary to obtain spherical harmonic functions for a large range of l. For example, the Mars topography data set can include harmonic degrees up to 100. If you pass a given l and m to the function plgndr in Numerical Recipes the result is just fine for l up to about 16 or 17. Of course, this result is ordinarily normalized by a factor so that it is orthonormal over the sphere. The problem is that for l =18 and higher the numbers involved (for m close to l) in plgndr become unmanageably large for straightforward computation. Trying to normalize these numbers with the factor after applying the routine gives very inaccurate results. Another source of inaccuracy is in the recursion used to calculate P(l,m,x) for l>m>1, which requires taking the difference of very large numbers, leading to errors attributable to round off.
After trying several different approaches, I have solved this problem by modifying the recursions used in plgndr to use the normalization factors during the calculations themselves at all levels. This ensures that the calculations will only involve numbers of the same order of magnitude as the spherical harmonic function that is being calculated. As a result, this type of calculation can give accurate and stable results for values of l well into the hundreds. It is actually a fairly simple fix, just multiply the recursions in the routine by the appropriate factors for the l=m part and the l>m part.
I do not know the rules for posting code in these forums, so I will abstain from posting my subroutine here. If you want to know how this is done or have any questions on this topic, then feel free to e-mail me at hernlund@ess.ucla.edu.
Cheers!
John Hernlund
In many calculations it is necessary to obtain spherical harmonic functions for a large range of l. For example, the Mars topography data set can include harmonic degrees up to 100. If you pass a given l and m to the function plgndr in Numerical Recipes the result is just fine for l up to about 16 or 17. Of course, this result is ordinarily normalized by a factor so that it is orthonormal over the sphere. The problem is that for l =18 and higher the numbers involved (for m close to l) in plgndr become unmanageably large for straightforward computation. Trying to normalize these numbers with the factor after applying the routine gives very inaccurate results. Another source of inaccuracy is in the recursion used to calculate P(l,m,x) for l>m>1, which requires taking the difference of very large numbers, leading to errors attributable to round off.
After trying several different approaches, I have solved this problem by modifying the recursions used in plgndr to use the normalization factors during the calculations themselves at all levels. This ensures that the calculations will only involve numbers of the same order of magnitude as the spherical harmonic function that is being calculated. As a result, this type of calculation can give accurate and stable results for values of l well into the hundreds. It is actually a fairly simple fix, just multiply the recursions in the routine by the appropriate factors for the l=m part and the l>m part.
I do not know the rules for posting code in these forums, so I will abstain from posting my subroutine here. If you want to know how this is done or have any questions on this topic, then feel free to e-mail me at hernlund@ess.ucla.edu.
Cheers!
John Hernlund