error handling for complex equation

3 次查看(过去 30 天)
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!

请先登录,再进行评论。

类别

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