error message: integral calculation

2 次查看(过去 30 天)
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 个评论
Torsten
Torsten 2022-11-26
编辑:Torsten 2022-11-26
So you set g = 1 and beta3 = 0 ?
You didn't give values to f, f1 and f2. If you use "integral", you must give numerical values to all the constants involved except z .
Or do you aim at a symbolic solution ? Then use "int".

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2022-11-26
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 个评论
Walter Roberson
Walter Roberson 2022-11-30
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);
柊介 小山内
柊介 小山内 2022-12-2
Thank you Walter and Torsten. If I face new question, I may ask you again.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by