Altering Default MaxFunEvals

조회 수: 6 (최근 30일)
Alex
Alex 2012년 2월 2일
편집: Gova ReDDy 2013년 9월 26일
Hi, I'm having trouble altering the default number of evaluations (300) of an fsolve. My .m file looks like this (function omitted):
function solveeqs()
guess=[1.6 0 300];
options = optimset('MaxFunEvals',1e10);
[result, fval, exit, output]=fsolve(@eqns, guess);
result
fval
eqns(guess)
exit
output
end
I thought that the options command might fix it, but the output defines the evaluation limit at 300 anyways. Any tips?

답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 2월 2일
You're not passing the options structure to fsolve()
options = optimset('MaxFunEvals',1e10);
[result, fval, exit, output]=fsolve(@eqns, guess,options);
Just make sure options is defined before you call fsolve.
  댓글 수: 3
Sean de Wolski
Sean de Wolski 2012년 2월 2일
The default maxfunevals is 100 times the number of variables. Can you post _exactly_ what you are running?
I would worry a little that there is something more seriously wrong if it has not converged after that nmany iterations.
Alex
Alex 2012년 2월 2일
The equations it's working on are very complex non-linear differential equations, but I'll post the code below, line for line, with the output:
function solveeqs()
guess=[1.6 0 300];
options = optimset('MaxFunEvals',1e10);
[result, fval, exit, output]=fsolve(@eqns, guess, options);
result
fval
eqns(guess)
exit
output
end
function fcns=eqns(z)
n=z(1);
k=z(2);
d=z(3);
fcns(1)=((((1-(n-1i.*k))./(1+(n-1i.*k)))+(((n-1i.*k)-(1.694-1i.*3.666))./((n-1i.*k)+(1.694-1i.*3.666))).*(exp(1).^(-2.*1i.*(2.*pi./250).*(n-1i.*k).*d)))./(1+((1-(n-1i.*k))./(1+(n-1i.*k))).*(((n-1i.*k)-(1.694-1i.*3.666))./((n-1i.*k)+(1.694-1i.*3.666))).*(exp(1).^(-2.*1i.*(2.*pi./250).*(n-1i.*k).*d))))-.922269;
fcns(2)=((((1-(n-1i.*k))./(1+(n-1i.*k)))+(((n-1i.*k)-(1.7046-1i.*3.7066))./((n-1i.*k)+(1.7046-1i.*3.7066))).*(exp(1).^(-2.*1i.*(2.*pi./251).*(n-1i.*k).*d)))./(1+((1-(n-1i.*k))./(1+(n-1i.*k))).*(((n-1i.*k)-(1.7046-1i.*3.7066))./((n-1i.*k)+(1.7046-1i.*3.7066))).*(exp(1).^(-2.*1i.*(2.*pi./251).*(n-1i.*k).*d))))-.92401;
fcns(3)=((((1-(n-1i.*k))./(1+(n-1i.*k)))+(((n-1i.*k)-(1.7152-1i.*3.7472))./((n-1i.*k)+(1.7152-1i.*3.7472))).*(exp(1).^(-2.*1i.*(2.*pi./252).*(n-1i.*k).*d)))./(1+((1-(n-1i.*k))./(1+(n-1i.*k))).*(((n-1i.*k)-(1.7152-1i.*3.7472))./((n-1i.*k)+(1.7152-1i.*3.7472))).*(exp(1).^(-2.*1i.*(2.*pi./252).*(n-1i.*k).*d))))-.925751;
end
Outputs:
run eqnsr
Solver stopped prematurely.
fsolve stopped because it exceeded the iteration limit,
options.MaxIter = 400 (the default value).
result =
1.0e+002 *
1.3445 + 5.5767i 5.5777 - 1.3435i 3.7721 + 3.5028i
fval =
1.0e-003 *
0.0734 - 0.9412i -0.0454 - 0.0117i -0.1829 + 0.9172i
ans =
-1.7380 - 0.1528i -1.7283 - 0.2051i -1.7148 - 0.2567i
exit =
0
output =
iterations: 400
funcCount: 1580
algorithm: 'trust-region dogleg'
firstorderopt: 5.9222e-004
message: [1x127 char]
Since this is a test of it's functionality (I know what values it should be returning (approximately), I'm concerned that it just isn't getting close enough. A result of .0011 isn't as close to 0 as I would like.

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

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by