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:
\[R^2 = \sum \frac{(y_{dat}-y_{fit})^2}{\sigma_{dat}^2}\]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.xvector of \(N\) independent variables,dat.yvector of \(N\) data values to be fitted,dat.evector of \(N\) standard deviation (positive numbers) used to weight the fit. If zero or missing1/dat.y^2will be assigned to each point.
func- Function handle with one of the following definition:
R2 = func(p)ifdatis empty,y = func(x,p)ifdatis a struct. Herexis a vector of \(N\) independent variables,pare the \(M\) parameters to be optimized andyis the simulated model,R2is the value to minimize.
Name-Value Pair Arguments
'lb'- Vector with \(N\) elements, lower boundary of the parameters. Default value is -inf.
'ub'- Vector with \(N\) elements, upper boundary of the parameters. Default value is inf.
'MaxIter'- Maximum number of iterations, default value is \(100M\).
'MaxFunEvals'- Maximum number of function evaluations, default value is \(1000M\). NOT IMPLEMENTED!
'TolX'- Convergence tolerance for parameters, default value is \(10^{-3}\).
'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
R2value (return value offuncor the weighted least square deviation from data). Default value is \(10^{-3}\).