Integral2 With Spherical Harmonics

5 vues (au cours des 30 derniers jours)
ADSW121365
ADSW121365 le 27 Mai 2019
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,:);
%% Normalisation:
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);
end
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;
end
end
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!

Réponse acceptée

Star Strider
Star Strider le 27 Mai 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);

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by