Integral2 With Spherical Harmonics
4 views (last 30 days)
I have a function to evaluate a specific spherical harmonic at some nth, mth order for some given Theta,Phi input. Currently I give numerical theta, phi inputs to evaluate these functions. What I would like to do is utalise matlabs integral function to perform integrations utalising this function (the problem is more detailed but I'm starting simple).
function [Ynm] = sphharmcomplex(n,m,Theta,Phi)
%sphharmcomplex - Takes a given n (or l),m and generates the corresponding
%complex spherical harmonic at a point Theta,Phi.
%% Legendre Polynomials P_nm(cos(theta)):
xn = cos(Theta); P_n = legendre(n,xn,'unnorm');
P_nm = P_n(abs(m)+1,:);
a = factorial(n-abs(m)); b = factorial(n+abs(m)); c =((2*n)+1)./(4*pi);
coeff = sqrt(a.*c./b);
%% Calculate Ynm:
Ynm = coeff .* P_nm .* exp(1i.*m.*Phi);
What I need to do is rewrite this function such I can assign a function handle to it for a integration of the form:
output = 0;
for n = 1:nlim
for m = -n:n
func = (@Theta, Phi) sphharmcomplex(n,m,Theta,Phi)
ans = integral2(func,Thetamin,Thetamax,Phimin,Phimax)
output = output + ans;
Is anyone able to help with the changes in syntax required to do this?
Currently it throws an error at the function handle assignment which I can't seem to fix. I believe I may need to convert the function to cartesian coordinates somewhere utalising
X = R.*sin(Theta).*cos(Phi); Y = R.*sin(Phi).*sin(Theta); Z =R.*cos(Theta);
but beyond that I'm really rather stuck.
Any help is greatly appreciated!
Star Strider on 27 May 2019
I can’t run your code because I don’t have all the variables.
The probllem is a typographical error in ‘func’.
Try this instead:
func = @(Theta, Phi) sphharmcomplex(n,m,Theta,Phi);