필터 지우기
필터 지우기

Integral2 With Spherical Harmonics

조회 수: 7 (최근 30일)
ADSW121365
ADSW121365 2019년 5월 27일
답변: Star Strider 2019년 5월 27일
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!

채택된 답변

Star Strider
Star Strider 2019년 5월 27일
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개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by