Matrix dimensions must agree for computing spherical harmonics !!!!

조회 수: 1 (최근 30일)
Ano
Ano 2017년 3월 9일
답변: Ano 2017년 3월 10일
Hi i am trying to calculate the spherical harmonic but I get an error saying that the matrices dimensions must agree, here is the code, any suggesions are very welcomed!
L=4;
theta =linspace(0,pi,5); %theta ranges from 0 to pi
phi =linspace(0, 2*pi,5); %phi ranges from 0 to 2*pi
for m=-L:L
cst = sqrt((2*L+1)*factorial(L-m)/((4*pi)*factorial(L+m))); %constant of spherical harmonics
P = legendre(L,cos(theta));
Y = cst.*P.*exp(-1j.*m.*phi);
end
  댓글 수: 2
Rahul Kalampattel
Rahul Kalampattel 2017년 3월 9일
I'm not getting any errors when I run your code in Matlab (R2016b). Which line were you having trouble with?
KSSV
KSSV 2017년 3월 10일
cst.*P.*exp(-1j.*m.*phi) In this P is 5x5 matrix, exp(-1j*m*phi) is 1x5..you expect output to be a matrix or array?

댓글을 달려면 로그인하십시오.

답변 (1개)

Ano
Ano 2017년 3월 10일
the output should be a matrix I have solve it by using the transpose of P now it works! Thank you!!

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by