error message: integral calculation
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
柊介 小山内
el 26 de Nov. de 2022
Comentada: 柊介 小山内
el 2 de Dic. de 2022
I want to calculate a formula as followed.
So I wrote a program as below. But in this program, error message" integralCalc/finalInputChecks (line 522). input function must be type of single or double. function hundle found." was displayed.
I tried to use fun1*fun2 in spite of fun, but error messages"function mtimes(input parameter of type 'function_handle' not defined.)" and integralCalc/finalInputChecks (line 314) displayed.
What should I do?
a = 0.2; %field loss coefficient α
y = 1.3; % fiber non-linearity coefficient γ
Ns = 20; %number of span
Ls = 100; %span length
b2 = 20.7; %dispersion coefficient
%% formula of ρ
PI = pi;
fun1 = @(z)exp(2*z-2*a*z);
Le = (abs((integral(fun1,0,100))))^2 ;%square of span effective length
fun = @(z,f,f1,f2)exp(1j*4*PI^2*(f1-f)*(f2-f)*b2*z)*exp(2*z-2*a*z);%fun1*fun2
%fun2 = @(f,f1,f2)exp(1j*4*PI^2*(f1-f)*(f2-f)*b2*z); %second element of integration
p = (abs(integral(@(z) fun,0,Ls)))^2/Le%ρ
Thank you.
1 comentario
Respuesta aceptada
Walter Roberson
el 26 de Nov. de 2022
p = (abs(integral(@(z) fun,0,Ls)))^2/Le%ρ
@(z)fun is an anonymous function that ignores its input argument and returns the anonymous function handle fun. It does not execute fun on the value of z. Just pass fun at that point instead of @(z)fun
18 comentarios
Walter Roberson
el 30 de Nov. de 2022
The below code takes several hours to run, mostly the last step. The function handle it produces starts with
@(f)exp(-3.96e+2./5.0).*integral(@(f2)integral(@(f1)exp(3.96e+2./5.0).*1.804851387845415e-35.*(
with the nested calls to integral(). It contains quite a number of very large coefficients beyond 1e250.
The portion I looked at did not have any calls to real() or imag() -- but I can only see a small portion because it is such a long expression.
If you do take this approach I recommend that you use the 'file' option for matlabFunction, and that you specifically ask for optimization to be false when you use the 'file' option (optimization has been producing incorrect results in recent MATLAB releases; I do not know if it is fixed in R2022b.)
This all gives you a NLI as a symbolic expression in f, and gives you NLIF as function handle to process values of f numerically. It is not a closed-form formula: you are unlikely to get a closed form formula unless you do something like taylor series (keeping in mind that taylr series of an exponential is pretty inaccurate unless you restrict the range of inputs a fair bit.)
alfa = 0.2; %field loss coefficient α
gamma = 1.3; % fiber non-linearity coefficient γ
Ns = 20; %number of span
Ls = 100; %span length
beta2 = 20.7; %dispersion coefficient
PI = sym(pi);
syms z f f1 f2
assume(z>0);
Le = (abs((int(exp(2*alfa-2*alfa*z),z,0,Ls))))^2;
assume(f,'real');
assume(f1,'real');
assume(f2,'real');
Le = ((int(exp(2*alfa-2*alfa*z),z,0,Ls)))^2;
p = (int(exp(1j*4*pi^2*(f1-f)*(f2-f)*beta2*z)*exp(2*z*(1-alfa)),z,0,Ls))^2;
p = real(p)^2*imag(p)^2;
p = expand(p)/Le;
%% formula of GNLI
%%p = matlabFunction(p);
pint1 = int(p,f1,-0.5,0.5); %integration about f1
pint2 = int(pint1,f2,-0.5,0.5); %integration about f2
NLI = (16/27)*gamma^2*Le*pint2; % NLI of 1span
NLIF = matlabFunction(NLI);
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!