No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
fminsearchbnd new

5.0 | 3 ratings Rate this file 15 Downloads (last 30 days) File Size: 5.52 KB File ID: #17804 Version: 1.0

fminsearchbnd new



29 Nov 2007 (Updated )

improved bounded fminsearch algorithm

| Watch this File

File Information

A minor improvement on the fminsearchbnd (bounded fminsearch) created by John D'Errico. Changes:

% Changes from fminsearchbnd:
Changes from fminsearchbnd:
1) in options structure, user may pass an 'output function' and 'plot function' to fminsearch.
Original fminsearchbnd handled the output function via a nested wrapper function. I have extended
this to the plot function too.
2) I have moved the 'intrafun' function and wrappers to be nested functions (INSIDE the
fminsearchbnd function), so they do not need to pass the params structure around (into
fminsearch) - but have access to it directly. This
maintains the integrity of the varargin, which the user may be passing thru fminsearch to their
optmization funciton (fminsearchbnd had passed the params structure to fminsearch, thus ruining any
varargin that the user passed in).
3) I have created a test example so the user can see not only how fminseachbnd works, but also how
the OutputFn and PrintFns functions work, which were heretofore poorly documented by MathWorks.


Fminsearchbnd, Fminsearchcon inspired this file.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
22 Jun 2016 Bojan

Bojan (view profile)

20 Jun 2011 Sina Tootoonian


I got the same problem. The cause seemed to be that intrafun passes varargin to the function to m inimize, and if the latter function can't handle it, an error is generated.

The workaround I found was to let my function accept varargin as a dummy argument e.g. If my function was f = @(x) x^2, to change it to f = @(x,varargin) x^2. When this is done, the new function can handle the varargin passed in through intrafun, and no error results.

Hope this helps!

Comment only
30 Nov 2009 Andrew

Andrew (view profile)

Has anybody been able to run this function in a parfor loop?

Comment only
22 May 2009 Chris Men

good job and thank you very much

29 Mar 2009 Andy

Andy (view profile)

I was going to use this code to fit Gaussians to a known curve by minimizing the known - fit residual. I tried for 3 and 4 Gaussians, meaning 9 or 12 variables. This newer code fails giving the error:

Too many input arguments.

Error in ==> fminsearchbnd>@(x,varargin)fun(xtransform(x),varargin{:}) at 233
intrafun = @(x, varargin) fun(xtransform(x), varargin{:});

Error in ==> fminsearch at 205
fv(:,1) = funfcn(x,varargin{:});

Error in ==> fminsearchbnd at 264
[xu,fval,exitflag,output] = fminsearch(intrafun,x0u,options,varargin);

The original code by John D'Errico works perfectly.

Comment only
04 Dec 2007 John D'Errico

I like the changes that Ken has made. They clean up the code nicely. Not much to say other than - well done.

30 Nov 2007 Ken Purchase

Thanks John - I realize I shipped it with a few bugs. I'll update it when I get to the office Monday.

Comment only
30 Nov 2007 John D'Errico

I'll get to a careful review of this asap, but until I do, I'll note that the optimization toolbox is listed as a requirement. Since fminsearch is part of Matlab, that toolbox should not be necessary. Until then, it looks like Ken has found some things to clean up in my code. If so, well done.

Comment only

Contact us