matlabargumentsfminsearch

MATLAB fminsearch with varargin


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.)


Solution

  • 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);