error handling for complex equation

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 个评论

I don't understand why pc-1-k is not a negtaive integer. k is defined to run and go to pc-1 at most, and pc is greater than 1 and integer.
As in the picture below, I am just trying to solve this equation for u= 2*r^2/w^2. I used symsum since I am calculating a series.
You have previously defined k as 2pi/wavelength. Try using a different symbol for this.
oh thank you, i see my mistake. :)
but now the variable that runs in the sum is undefined (for k replace variable n). This variable runs with the sum and is therefore also defined, what have I misunderstood?
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!

请先登录,再进行评论。

类别

帮助中心File 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