Help with 'fminsearch'
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
Oleg Komarov
2012 年 5 月 9 日
Usually oprimization routines all have a varargin input. Edit fminsearch or fminbnd.
回答 (2 件)
Oleg Komarov
2012 年 5 月 9 日
P = fminsearch(errfh,p0,optimset('MaxFunEvals',1000),t,rel)
2 件のコメント
Oleg Komarov
2012 年 5 月 9 日
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.
Walter Roberson
2012 年 5 月 9 日
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 件のコメント
Walter Roberson
2012 年 5 月 9 日
Guessing about what you are trying to pass to what:
P = fminsearch(@(p) errfh(p,t,rel), p0, optimset('MaxFunEvals',1000));
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!