Integral2 With Spherical Harmonics
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ADSW121365
am 27 Mai 2019
Beantwortet: Star Strider
am 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!
0 Kommentare
Akzeptierte Antwort
Star Strider
am 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);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!