Syntax
[pOpt,fVal,stat] = ndbase.simplex([],func,p0,Name,Value)
[pOpt,fVal,stat] = ndbase.simplex(dat,func,p0,Name,Value)
Description
[pOpt,fVal,stat] = ndbase.simplex([],func,p0,Name,Value)
finds a
minimum of a function of several parameters using the constrained simplex
optimization algorithm by calling the unconstrained Matlab built-in
algorithm fminsearch.
The function has two different modes, depending on the first input
argument. If dat
is empty, simplex
minimizes the cost function func,
that has the following header:
R2 = func(p)
If dat
is a struct, simplex
optimizes the model defined by func
via
least squares to the data stored in dat
. In this case func
has the
following header:
yModel = func(x,p)
And the least square deviation is defined by:
simplex
may
try to evaluate the function exactly at zero.Examples
Example usage on the rosen function.
rosen = @(x) (1-x(1)).^2 + 105*(x(2)-x(1).^2).^2
Unconstrained optimisation:
fminsearch(rosen,[3 3])
Output
1.0000 1.0000
Constrained optimisation:
ndbase.simplex([],rosen,[3 3],'lb',[2 2],'ub',[])
Output
2.0000 4.0000
Input Arguments
dat
- Either empty or contains data to be fitted stored in a structure with
fields:
dat.x
vector of independent variables,dat.y
vector of data values to be fitted,dat.e
vector of standard deviation (positive numbers) used to weight the fit. If zero or missing1/dat.y^2
will be assigned to each point.
func
- Function handle with one of the following definition:
R2 = func(p)
ifdat
is empty,y = func(x,p)
ifdat
is a struct. Herex
is a vector of independent variables,p
are the parameters to be optimized andy
is the simulated model,R2
is the value to minimize.
Name-Value Pair Arguments
'lb'
- Vector with elements, lower boundary of the parameters. Default value is -inf.
'ub'
- Vector with elements, upper boundary of the parameters. Default value is inf.
'MaxIter'
- Maximum number of iterations, default value is .
'MaxFunEvals'
- Maximum number of function evaluations, default value is . NOT IMPLEMENTED!
'TolX'
- Convergence tolerance for parameters, default value is .
'Display'
- Level of information to print onto the Command Line during
optimisation. Possible values are
'off'
,'notify'
and'iter'
. Default value is'off'
. 'TolFun'
- Convergence tolerance on the
R2
value (return value offunc
or the weighted least square deviation from data). Default value is .