Help with 'fminsearch'

Hi
I am fitting an exponential to my data using least squares, as in:
************************************************************
t = 0:7 ;
rel = [629 537 460 375 334 286 249 227];
fh = @(x,p) p(1) + p(2)*exp(-x./p(3))
errfh = @(p,x,y) sum((y(:)-fh(x(:),p)).^2)
p0 = [mean(rel) (max(rel)-min(rel)) (max(t) - min(t))/2];
P = fminsearch(errfh,p0,[],t,rel)
plot(t,rel,'bo',t,fh(t,P),'r-')
************************************************************
However, now I wish to increase MaxFunEvals. How can I do this, when I use fminsearch in this fashion?
Best, Niles.

5 comentarios

Sargondjani
Sargondjani el 9 de Mayo de 2012
wow, i have never seen this: you supply the x (t) and y (rel) after the options. i can't find it in the documentation either
where did you learn this??
Niles Martinsen
Niles Martinsen el 9 de Mayo de 2012
I learned it here: http://www.mathworks.com/matlabcentral/newsreader/view_thread/169601
Sargondjani
Sargondjani el 9 de Mayo de 2012
hmmm... not much documentation there either, haha. it's interesting... i really wonder if this also works for other optimization algoritms. it would be very nice if you could pass the parameters after the optimset
Oleg Komarov
Oleg Komarov el 9 de Mayo de 2012
Usually oprimization routines all have a varargin input. Edit fminsearch or fminbnd.
Walter Roberson
Walter Roberson el 9 de Mayo de 2012
In 2008, Jos sometimes made mistakes.

Iniciar sesión para comentar.

Respuestas (2)

Oleg Komarov
Oleg Komarov el 9 de Mayo de 2012

0 votos

P = fminsearch(errfh,p0,optimset('MaxFunEvals',1000),t,rel)
Check the documentation for optimset

2 comentarios

Niles Martinsen
Niles Martinsen el 9 de Mayo de 2012
I tried this out, but it did not have the desired effect unfortunately.
Oleg Komarov
Oleg Komarov el 9 de Mayo de 2012
What do you mean it did not have the desired effect?
Try to reduce it to 10 or 50. Keep in mind it's a local solver.

Iniciar sesión para comentar.

Walter Roberson
Walter Roberson el 9 de Mayo de 2012

0 votos

You cannot increase MaxFunEvals when you use fminsearch in that fashion, as fminsearch takes a maximum of 3 inputs, not the 5 you are using. The function handle you provide to fminsearch must take exactly one argument. The initial guess follows the function handle, and the options structure (if provided) follows that.

4 comentarios

Niles Martinsen
Niles Martinsen el 9 de Mayo de 2012
Thanks, I'll try it out.
Best,
Niles.
Oleg Komarov
Oleg Komarov el 9 de Mayo de 2012
@Walter: I don't get it.
Isn't fminsearch treating x (t) and y (rel) as 'data' and optimizing wrt to p?
Niles Martinsen
Niles Martinsen el 9 de Mayo de 2012
Walter, actually when I think it over I am not sure I understand what you mean.
Walter Roberson
Walter Roberson el 9 de Mayo de 2012
Guessing about what you are trying to pass to what:
P = fminsearch(@(p) errfh(p,t,rel), p0, optimset('MaxFunEvals',1000));

Iniciar sesión para comentar.

Categorías

Más información sobre Optimization en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 9 de Mayo de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by