### 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:

### 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 $N$ independent variables,
• dat.y vector of $N$ data values to be fitted,
• dat.e vector of $N$ standard deviation (positive numbers) used to weight the fit. If zero or missing 1/dat.y^2 will be assigned to each point.
func
Function handle with one of the following definition:
• R2 = func(p) if dat is empty,
• y = func(x,p) if dat is a struct. Here x is a vector of $N$ independent variables, p are the $M$ parameters to be optimized and y is the simulated model, R2 is 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 R2 value (return value of func or the weighted least square deviation from data). Default value is $10^{-3}$.