Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
0 of .
Results for:
P. 1
Mathematica - Spherical Harmonics

# Mathematica - Spherical Harmonics

Ratings: (0)|Views: 459 |Likes:

### Availability:

See more
See less

08/17/2013

pdf

text

original

In[46]:=
Normalization part of spherical harmonics
shNormalizationCoeffs
l_, m_
:
Sqrt

2
l
1
l
m
4
Pi
l
m

Evaluates to a function of
Θ
,
Φ
for a given degree l and order m,it's defined as three different cases for
0,
0, and
0
shGetFn
l_, m_
:
Simplify
Piecewise

shNormalizationCoeffs
l, 0
LegendreP
l, 0, Cos
Θ

,
0
,
Sqrt
2
shNormalizationCoeffs
l,
Cos
m
Φ
LegendreP
l, m, Cos
Θ

,
0
,
Sqrt
2
shNormalizationCoeffs
l,
m
Sin
m
Φ
LegendreP
l,
m, Cos
Θ

,
0

Indices for a SH of a given degree, applies a function whichcreates a range from
x to x to every element of the range 0...l,return a list of lists. Note that body& is one of Mathematica's way to express pure function, with parameters
1,
2... fn
list is the shorthand for Map
fn,list
shIndices
l_
:
Range
1,
1
&
Range
0, l
For each element of the shIndices list,it replaces the corresponding shGetFn
This is tricky. MapIndexed takes a functionof two parameters: element of the list and index in thelist. Our function is itself a function applied to a list,as our elements are lists
shIndices is a list of lists
shFunctions
l_
:
MapIndexed

list, currLevel

m
shGetFn
currLevel
1,

list
, shIndices
l

Generates SH coefficients of a given function fn of
Θ
,
Φ
,it needs a list of SH bases obtained from shFunctions,it will perform spherical integration between fn and each of the SH functions
shGenCoeffs
shfns_, fn_
:
Map
Integrate
1
fn
Θ
,
Φ
Sin
Θ
,
Θ
, 0, Pi
,
Φ
, 0, 2
Pi

&, shfns
From SH coefficients and shFunctions it will generate a function of
Θ
,
Φ
which is the SH representation of the given coefficients. Note the use ofassumptions over
Θ
and
Φ
passed as options to Simplify to be able toreduce the function correctly,

is the shorthand of Apply
fn,params
angleVarsDomain
Element
Θ
, Reals
,Element
Φ
, Reals
,
Θ
0,
Φ
0,
Θ
Pi,
Φ
2
Pi
;shReconstruct
shfns_, shcoeffs_
:
Simplify
Plus

Flatten
shcoeffs
Flatten
shfns

, Assumptions
angleVarsDomain
Let's test what we have so far
testNumLevels
2;shfns
shFunctions
testNumLevels
testFn
Θ
_,
Φ
_
:
Cos
Θ
^10
UnitStep
Cos
Θ

Simple, symmetric around the z
axis
generate coefficients and reconstructed SH function
testFnCoeffs
shGenCoeffs
shfns, testFn
testFnSH
Θ
,
Φ
Evaluate
shReconstruct
shfns, testFnCoeffs

plot original and reconstruction
SphericalPlot3D

testFn
Θ
,
Φ
, testFnSH
Θ
,
Φ

,
Θ
, 0, Pi
,
Φ
, 0, 2
Pi
, Mesh
False, PlotRange
Full

Out[9]=

12
Π

,

123
Π
Sin
Θ
2
Sin
Φ

,
123
Π
Cos
Θ

,
123
Π
Cos
Φ
Sin
Θ
2

,

1215
Π
Cos
Φ
Sin
Θ
2
Sin
Φ

,
1215
Π
Cos
Θ
Sin
Θ
2
Sin
Φ

,
185
Π
1
3 Cos
2
Θ

,
1215
Π
Cos
Θ
Cos
Φ
Sin
Θ
2
,
1415
Π
Cos
2
Φ
Sin
Θ
2

Out[11]=

Π
11

,

0
,
Π
3
4
,
0

,

0
,
0
,
10 5
Π
143
,
0
,
0

Out[12]=
Function

Θ
,
Φ
,Cos
Θ
8
3572
17
25 Cos
2
Θ

Out[13]=
2

SH_Test.nb

In[28]:=
Checks if a given set of coefficients corresponds to zonal harmonics
shIsZonal
shcoeffs_, l_
:
Plus

Flaten
shIndices
l

Flatten
shcoeffs

0
Some utility functions
shSymConvolveNormCoeffs
l_
:
MapIndexed

list, currLevel
Table
Sqrt
4
Pi
2
currLevel
1

,
Length
list

, shIndices
l

shExtractSymCoeffs
shcoeffs_
:
Table
1

Ceiling
Length
1
2

,
Length
1

&
shcoeffs
Convolution with a kernel expressed via zonal harmonics,symmetric around the z
axis
shSymConvolution
shcoeffs_, shsymkerncoeffs_, l_
:
Check
shIsZonal
shsymkerncoeffs
, err
;shSymConvolveNormCoeffs
l
shcoeffs
shExtractSymCoeffs
shsymkerncoeffs

In[59]:=
Another test
testFn2
Θ
_,
Φ
_
:
UnitStep
Cos
Θ
Sin
Φ
 
asymmetric
testFn2Coeffs
shGenCoeffs
shfns, testFn2
testFn2SH
Θ
,
Φ
Evaluate
shReconstruct
shfns, testFn2Coeffs

plotFn2
SphericalPlot3D
testFn2
Θ
,
Φ
,
Θ
, 0, Pi
,
Φ
, 0, 2
Pi
, Mesh
False, PlotRange
Full
plotFn2SH
SphericalPlot3D
testFn2SH
Θ
,
Φ
,
Θ
, 0, Pi
,
Φ
, 0, 2
Pi
, Mesh
False, PlotRange
Full
Show
plotFn2, plotFn2SH
Test convolution
shIsZonal
testFnCoeffs, testNumLevels
testConvolvedCoeffs
shSymConvolution
testFn2Coeffs, testFnCoeffs, testNumLevels
testFnConvolvedSH
Θ
,
Φ
Evaluate
shReconstruct
shfns, testConvolvedCoeffs

plotConvolvedSH
SphericalPlot3D
testFnConvolvedSH
Θ
,
Φ
,
Θ
, 0, Pi
,
Φ
, 0, 2
Pi
, Mesh
False, PlotRange
Full
Out[60]=

Π

,

0
,
0
,
0

,

0
,
253
Π
,
0
,
0
,
0

Out[61]=
Function

Θ
,
Φ
,
Π
5 Sin
2
Θ
Sin
Φ
2
Π
SH_Test.nb
3