Altering Default MaxFunEvals

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?

Respuestas (1)

Sean de Wolski
Sean de Wolski el 2 de Feb. de 2012

0 votos

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 comentarios

Alex
Alex el 2 de Feb. de 2012
I've defined it as above, and it accepts it, but my function evaluation limit still isn't increasing. It now says 400 evaluations instead of 300, but still defines 400 as the default. I'm at a different computer now though, so maybe that makes sense.
Sean de Wolski
Sean de Wolski el 2 de Feb. de 2012
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 el 2 de Feb. de 2012
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.

Iniciar sesión para comentar.

Preguntada:

el 2 de Feb. de 2012

Editada:

el 26 de Sept. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by