MATLAB How can I program spherical harmonics in MATLAB?

AI Thread Summary
Programming spherical harmonics in MATLAB involves creating a double summation that incorporates the spherical harmonics function, which can be derived from associated Legendre functions. While MATLAB does not have a built-in spherical harmonic function, users can implement it using the definitions found in mathematical resources. For higher-order derivatives, MATLAB's "diff" function can approximate derivatives, but caution is advised due to the nature of numerical derivatives. It is also suggested to explore MATLAB's extensive code resources for additional guidance. Understanding these concepts will aid in effectively programming spherical harmonics and their derivatives in MATLAB.
scarecrow
Messages
139
Reaction score
0
I would appreciate some input about how to program spherical harmonics in Matlab.

http://mathworld.wolfram.com/SphericalHarmonic.html

I want to program a double summation that looks like this.

<br /> <br /> G(\Omega_{1},t_{1}|\Omega_{0}) = \sum_{l=0}^\infty \sum_{m=-l}^l \alpha^m_{l}(t_{1}) [\Gamma^m_{l}(\Omega_{0})]^* \Gamma^m_{l}(\Omega_{1})<br />

where \Gamma^m_{l}(\Omega_{i}) is a spherical harmonic and \alpha^m_{l} depends on l, m, and t.

Is there a spherical harmonic function in Matlab? I couldn't find anything except the Legendre polynomials.
 
Physics news on Phys.org
This is a follow up question. I'm a beginner in Matlab, so please excuse my ignorance if these questions seem stupid. How would you program higher-order derivatives into for loops? Is there a syntax in Matlab for higher-order derivatives?

for l = 0:5
for m = -l:l

\frac {d^{l+m}} {dx^{l+m}} (x^2-1)^l
 
Do a search on the MATLAB site, they have an abundance of code for you to look at...
 
Hey
Derivatives can be approximated by differences which is done by the command diff(x,k) where "x" is a vector and k is the order. Hence k=1 corresponds to the first order derivative of x.
Maybe this can help you further.
 
eys_physics said:
Hey
Derivatives can be approximated by differences which is done by the command diff(x,k) where "x" is a vector and k is the order. Hence k=1 corresponds to the first order derivative of x.
Maybe this can help you further.

True, but you have to be very very careful with numerical derivatives (they are a local entity as opposed to numerical integration which is more global in nature). Many special functions are better evaluated using recurrence relations.
 
thanks for the tips.
 
Back
Top