# Spherical Harmonics in MATLAB

1. Oct 22, 2008

### scarecrow

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.

$$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})$$

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.

2. Oct 22, 2008

### Dr Transport

The definition of the spherical harmonics are found here

http://en.wikipedia.org/wiki/Spherical_harmonics

which are a product of the Associated Legendre functions and a phase factor...... this should be straight forward to program in MatLAB

3. Oct 23, 2008

### scarecrow

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$$

4. Oct 25, 2008

### Dr Transport

Do a search on the MATLAB site, they have an abundance of code for you to look at.....

5. Oct 25, 2008

### eys_physics

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.

6. Oct 25, 2008

### Dr Transport

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.

7. Oct 26, 2008

### scarecrow

thanks for the tips.