Maximum number of function evaluations has been exceeded - increase MaxFunEvals option.
Show older comments
Dear Matlab users: I've got a following problem: I try to find parameters of this function:

by simplex method (see the following code)
format compact
format long
xdata = [0.000,0.200,0.400,0.600,0.800,1.000,1.200,1.400,1.600,1.800,2.000,2.200,2.400,2.600,2.800,3.000,3.200,3.400,3.600,3.800,4.000,4.200,4.400,4.600,4.800,5.000];
ydata = [0.007,0.041,0.165,0.449,0.816,0.982,0.741,0.212,-0.362,-0.808,-0.975,-0.774,-0.290,0.290,0.775,0.982,0.849,0.527,0.237,0.077,0.018,0.003,0.000,0.000,0.000,0.000];
%Function to calculate the sum of residuals for our a given parameters
fun= @(p) sum(ydata - (-1*(p(1)-p(2)*(((xdata)-p(3))).^4).*(exp(-1*p(4)*((xdata)-p(3)).^2))).^2);
%starting guess for our parameters
%starting guess
pguess = [1.0,12.0,1.0,2.0];
%optimise
[p,fminres] = fminsearch(fun,pguess)
Unfortunately it doesn't work very well because this type of message appears:
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
Current function value: -Inf
I know that parameters, should be cca a= 1.0; b=12; c=2.4 and r=1.02 (in code, abcr parameters are p(1)...(p4)).
I need to use simplex method for iteration, so I try to fix this problem, but I am totaly newbie in matlab and don't know how to fix it.
Does anybody have any suggestion??
Thanks
Paul
Answers (2)
Matt J
on 7 Aug 2014
3 votes
Using the optimset command you can change MaxFunEvals and other algorithm parameters of fminsearch. You can also use optimoptions if you have the Optimization Toolbox.
2 Comments
Pavol Namer
on 7 Aug 2014
Edited: Matt J
on 7 Aug 2014
Alan Weiss
on 7 Aug 2014
You cannot use optimoptions for fminsearch, you have to use optimset. For example,
options = optimset('MaxFunEvals',1000);
[p,fminres] = fminsearch(fun,pguess,options)
Alan Weiss
MATLAB mathematical toolbox documentation
mura0087
on 20 Jan 2021
0 votes
I have this same problem! Even if I change MaxFunEvals to a very high number (1e30) I still get an Inf value out of fminsearch.
4 Comments
Walter Roberson
on 20 Jan 2021
The initial points tested all generated inf, so fminsearch() does not know which direction to look in.
You should give an initial point that has a finite value associated.
mura0087
on 20 Jan 2021
I had been giving the initial points as rand(2,1) but that's clearly not cutting it.
I am using fminsearch to minimize the error function of an implicit equation to my dataset. Some more information on what I did for that- is here. The fit works fine on data that I generated using the implicit function (sanity check), I can obtain values for the coefficients, but will NOT fit my experimental data.
I have not ruled out that my experimental data does not fit, or requires some sort of transformation. I do know, based on messing around with generating data with different coefficients, that the fminsearch is fairly sensitive to the start points I give it. Sometimes I need to give it values close to where I know the coefficients are.
Problem is, for the experimental data, I expect one of the coeffs to be between 0 and 1 (can make a reasonable guess here), but the other coeff needs be above 0 (too many options for me to get a good guess).
I am going to revisit the model to see if I can get a better understanding of what my coeffs should be, and set better guesses. Or loop over many, many guesses
Walter Roberson
on 20 Jan 2021
In the File Exchange, John D'Errico has a bounded version of fminsearch.
mura0087
on 20 Jan 2021
awesome, thank you!
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!