I want to increase 'maxFunEvals' in my program, but it doesn't work. What is the problem of my program?
clear all;
a = 0.2; %field loss coefficient α[db/km]
alfa = a*log(20)/20;
gamma = 1.3; % fiber non-linearity coefficient 
Ns = 20; %number of span
Ls = 100; %span length[km]
beta2 = 20.7; %dispersion coefficient[ps^2/km]
roll = 0.3; %roll-off of gwdm
%% formula of ρ
syms f f1 f2 real %f,f1,f2 is THz
Le = (1-exp(-2*alfa*Ls))/(2*alfa);
x1(f1,f2,f) = 1-exp(-2*alfa*Ls)*exp(4j*(pi^2)*(f1-f)*(f2-f)*beta2*Ls);%symfun
x2(f1,f2,f) = 2*alfa-(4j*(pi^2)*(f1-f)*(f2-f)*beta2);
p(f1,f2,f) = Le^(-2)*(abs(x1(f1,f2,f)/x2(f1,f2,f)))^2;
%% formula of Gwdm
syms t w k
T=1/(32e-3);
A = pi*t/T;
x(t)= (sin(A)/A)*(cos(roll*A)/(1-(2*roll*t/T)^2));
X(w) = simplify(fourier(rewrite(x(t),'exp'),t,w));
X(f) =X(2*sym(pi)*f);
X(f)= rewrite(abs(X(f)),'sqrt');
xfunc = matlabFunction(X(f));%@(f)
GWDM(f)= (symsum(xfunc(f+(50e-3)*k),k,-5,5)/((32/8.8)*T));
func = p*GWDM(f1)*GWDM(f2)*GWDM(f1+f2-f);
ft=matlabFunction(func);
%% formula of GNLI
pint = @(f)integral2(@(f1,f2)ft(f1,f2,f),-270.8e-3,270.8e-3,-270.8e-3,270.8e-3,'MaxFunEvals',20000);
NLI = @(f)(16/27).*Ns.^1.03.*gamma.^2.*Le.^2.*pint(f); % NLI
%f = -0.3:0.005:0.3;
%plot(f,arrayfun(@(f)NLI(f),f));
%hold on
%plot(f,GWDM(f));
%hold off

댓글 수: 5

Rik
Rik 2022년 12월 19일
What do you mean exactly with 'doesn't work'? I formatted your code as code so it can be run in the editor, which didn't return an error.
Have a read here and here. It will greatly improve your chances of getting an answer.
Torsten
Torsten 2022년 12월 19일
편집: Torsten 2022년 12월 19일
Look at the documentation.
AbsTol, RelTol and Method are the name-value arguments for "integral2". MaxFunEvals doesn't exist for "integral2".
Matt J
Matt J 2022년 12월 19일
I run my code and error message 'invalid name and value argument 'MaxFunEvals'. unrecognized name 'MaxFunEvals'. name must be 'AbsTol','RelTol' or 'Method'. ' displayed.
Your code does not demonstrate the error you are seeing, however, because you removed the lines that invoke pint
柊介 小山内
柊介 小山内 2022년 12월 19일
편집: 柊介 小山内 2022년 12월 19일
Sorry my program was wrong. if you fix formula of GNLI in my code as below, warning message 'you have reached the maxmum number of function evaluations(10000). the result didn't pass global error test.' will display. I think this warning can solve by increasing MaxFunEvals. but I can't increase the value.
pint = @(f)integral2(@(f1,f2)ft(f1,f2,f),-270.8e-3,270.8e-3,-270.8e-3,270.8e-3);
NLI = @(f)(16/27).*Ns.^1.03.*gamma.^2.*Le.^2.*pint(f); % NLI
NLI(0.165)
I tried to increase value as below, but didn't increase.
options = optimset('MaxFunEvals',20000);
pint =@(f)integral2(@(f1,f2)ft(f1,f2,f),-270.8e-3,270.8e-3,-270.8e-3,270.8e-3);
NLI = @(f)(16/27).*Ns.^1.03.*gamma.^2.*Le.^2.*pint(f); % NLI
fminsearch(NLI,0.165,options);
Torsten
Torsten 2022년 12월 19일
I suggest you plot NLI for reasonable values of f to see how the function behaves.

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

 채택된 답변

Matt J
Matt J 2022년 12월 19일
편집: Matt J 2022년 12월 19일

0 개 추천

The problem is that integral2 does not support an option called 'MaxFunEvals'. You imagined somehow that it does.

댓글 수: 2

Matt J
Matt J 2022년 12월 19일
편집: Matt J 2022년 12월 19일
pint = @(f)integral2(@(f1,f2)ft(f1,f2,f),-270.8e-3,270.8e-3,-270.8e-3,270.8e-3,...
'AbsTol',1e-7);
NLI = @(f)(16/27).*Ns.^1.03.*gamma.^2.*Le.^2.*pint(f); % NLI
NLI(0.165)
ans = 0.0037
I am sorry for digging up a subject from 3 years ago, but when i opened integral2.m, in line 105 it is calling integral2Calc.m
Opening this program, I can see examples that can be run in order to reproduce the warnings. for example:
elseif maxNFEWarn
if ERRBND > max(ATOL,RTOL*abs(Q))
% Example:
% integral2(@(x,y)single(1./(x+y)),0,1,0,1,'Abstol',1e-4,'MaxFunEvals',3)
warning(message('MATLAB:integral2:maxFunEvalsFail',maxFunEvals));
if opstruct.ThrowOnFail
error(message('MATLAB:integral2:unsuccessful'));
end
else
% Example:
% integral2(@(x,y)single(1./(x+y)),0,1,0,1,'Abstol',1e-4,'MaxFunEvals',4)
warning(message('MATLAB:integral2:maxFunEvalsPass',maxFunEvals));
end
elseif minRectWarn
if ERRBND > max(ATOL,RTOL*abs(Q))
% Example:
% integral2(@(x,y)single(1./(x+y)),0,1,0,single(1),'Abstol',1e-5)
warning(message('MATLAB:integral2:minRectSizeFail'));
if opstruct.ThrowOnFail
error(message('MATLAB:integral2:unsuccessful'));
end
As you can see, the examples use 'MaxFunEvals',X as option of the function. However, as you mentioned and as I was able to confirm I am unable to run integral2 with it as an option, becouse it produces an error. Was it a plan to make it an option that was never realised, and someone just forgot to delete it from the code?
I am using matlab 2022b
thank you

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

질문:

2022년 12월 19일

댓글:

2025년 4월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by