error handling for complex equation

조회 수: 3 (최근 30일)
Anna-Lena Geppert
Anna-Lena Geppert 2021년 5월 7일
댓글: Anna-Lena Geppert 2021년 5월 10일
Hey,
My problem is that there is an error message to Laguerrsche, firstly because of a matrix multiplication and secondly that the second input of n over k has to be non negative. However, the input is at most 0, since k runs to pc-1. And all values are scalar, if then possibly the r value would be a vector. I see therefore no solution for the indicated problems and thank you in advance for the answer(s).
% Define the fibre characteristics and wavelength
nCore = 1.434;
nCladding = 1.42;
wavelength = 1.23; % microns
coreRadius = 25; % microns(Mü-meter)
% Calculate fibre V number
V = (2*pi*coreRadius/wavelength)*sqrt(nCore^2-nCladding^2);
% Calculate wavenumber
k = 2 * pi / wavelength;
% Calculate Fleckradius
wf = sqrt(2*coreRadius^2/V);
iL=1;
pc =3;
r= [0,0.00001,0.005];
Laguerrsche = symsum(nchoosek(pc-1+iL,pc-1-k)*(-2*r.^2/wf^2)^k/factorial(k), k,0, pc-1);
YFeld= sqrt(factorial(pc-1)*pi/factorial(p-1+iL)) *1/wf* Laguerrsche*exp(-x^2/wf^2)*(sqrt(2)*x/coreRadius)^iL;
plot(r,YFeld)

답변 (1개)

Alan Stevens
Alan Stevens 2021년 5월 8일
nchoosek(pc-1+iL,pc-1-k) Your value of pc-1-k isn't a non-negative integer, but it needs to be for nchoosk.
Also why use symsum rather than just sum?
  댓글 수: 5
Alan Stevens
Alan Stevens 2021년 5월 9일
How about
% Define the fibre characteristics and wavelength
nCore = 1.434;
nCladding = 1.42;
wavelength = 1.23; % microns
coreRadius = 25; % microns(Mü-meter)
% Calculate fibre V number
V = (2*pi*coreRadius/wavelength)*sqrt(nCore^2-nCladding^2);
% Calculate wavenumber
k = 2 * pi / wavelength;
% Calculate Fleckradius
wf = sqrt(2*coreRadius^2/V);
iL=1;
pc =3;
r= [0,0.00001,0.005];
Laguerrsche = 0;
for n = 0:pc-1
Laguerrsche = nchoosek(pc-1+iL,pc-1-n)*(-2*r.^2/wf^2).^n/factorial(n)+Laguerrsche;
end
YFeld= sqrt(factorial(pc-1)*pi/factorial(pc-1+iL)) *1/wf* Laguerrsche.*exp(-r.^2/wf^2).*(sqrt(2)*r/coreRadius).^iL;
plot(r,YFeld)
Note that in YFeld you had x, which was undefined. I've replaced it by r in the above, though that's just guesswork on my part!
Anna-Lena Geppert
Anna-Lena Geppert 2021년 5월 10일
okay, thank you. :)

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

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by