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