2

The MATLAB documentation for fminsearch does not include a form like

x = fminsearch(fun,x0,options,varargin)

but such a form exists; I have used it. For example:

function[z] = myFunction(x,a,b,c)
    z = a * x^2 + b * x + c;
end

x0 = 0.0;
a = 2;
b = -6;
c = 10;
[x,z] = fminsearch(@myFunction,x0,[],a,b,c)

Is there some important reason why this is omitted from the docs? Is there another good reference where this is described, that I can point my students to? (There is a bit of documentation here, but this is not really what I'm looking for.)

LarrySnyder610
  • 2,277
  • 12
  • 24
  • 1
    There are a lot of undocumented bits and pieces of MATLAB. Some of it is because it's in development and testing, some of it just hasn't made it into the docs yet, and some of it just sneaks in. I've used this form of fminsearch quite a few times and find it much easier to use than the method recommended in the documentation. There is an entire [blog](http://undocumentedmatlab.com/) devoted to such hidden "features". – craigim Sep 12 '14 at 15:11
  • FYI, this deprecated form is a vestige of old versions of Matlab. It just remains for reasons of backwards compatibility. The same sort of form still exists for functions in the ODE suite (e.g., `ode45`). However it's much better to use [anonymous functions to parametrize your functions](http://www.mathworks.com/help/matlab/math/parameterizing-functions.html), as in @ChrisTaylor's answer – the resulting code will likely be faster and match current standards/documentation. – horchler Feb 13 '16 at 20:44

1 Answers1

0

I don't know why this form of calling fminsearch isn't in the docs - you'd have to ask someone who works for MathWorks. However, if you want to call functions with extra parameters and conform to the documentation, you could just do

x0 = 0.0;
a = 2;
b = -6;
c = 10;

[x,z] = fminsearch(@(x) myFunction(x,a,b,c), x0);
Chris Taylor
  • 46,912
  • 15
  • 110
  • 154