How can I program spherical harmonics in MATLAB?

Click For Summary

Discussion Overview

The discussion revolves around programming spherical harmonics in MATLAB, focusing on the implementation of a double summation involving spherical harmonics and their derivatives. Participants seek guidance on coding techniques and mathematical definitions relevant to this topic.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant requests assistance in programming a specific double summation involving spherical harmonics and expresses difficulty in finding a built-in function for spherical harmonics in MATLAB.
  • Another participant provides a definition of spherical harmonics, indicating they are products of associated Legendre functions and phase factors, suggesting that programming them should be straightforward.
  • A follow-up question arises regarding the programming of higher-order derivatives in MATLAB, with a participant asking about the syntax for implementing these derivatives using for loops.
  • One participant suggests searching the MATLAB site for existing code related to spherical harmonics.
  • Another participant mentions that derivatives can be approximated using the MATLAB command diff(x,k), where "x" is a vector and "k" is the order of the derivative.
  • A later reply cautions about the careful use of numerical derivatives, noting that they are local entities and suggesting that many special functions might be better evaluated using recurrence relations.

Areas of Agreement / Disagreement

Participants express varying levels of familiarity with MATLAB and programming concepts, and while some provide suggestions and resources, there is no consensus on the best approach to programming spherical harmonics or higher-order derivatives.

Contextual Notes

Participants have not fully resolved the question of how to implement spherical harmonics in MATLAB, and there are uncertainties regarding the best practices for numerical derivatives and the availability of built-in functions.

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.

[tex] <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})[/tex]

where [tex]\Gamma^m_{l}(\Omega_{i})[/tex] is a spherical harmonic and [tex]\alpha^m_{l}[/tex] 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

[tex]\frac {d^{l+m}} {dx^{l+m}} (x^2-1)^l[/tex]
 
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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
3
Views
3K