Grocer optimization function
[valf,b1,valg]=optimg(f,fg,b0,optim_opt,nelmead_opt,gradconv)
* f = the function to minimize
* g = the function to minimize, with gradient vector calculated as second output argument
* b0 = a (k x 1) vector, the vector of starting values
* optim_opt = a string, any options to optim entered but entered between quotes
* nelmead_opt = a string, the values of the convergence criterion, followed by the maximum number of iterations, the figure being separated by a comma
* gradconv = a positive number, the convergence criterion of the absolute mean of the gradient components
* valf = the value of the function at the solution
* b1 = the value of the solution vector of parameters
* valg = the value of the gradient at the solution
function valf=f(b, y, x) valf=sum((y-b(1)*(1-exp(-b(2)*x)))^2) endfunction function [valf, valg, ind]=fg(b, ind) valf=sum((y-b(1)*(1-exp(-b(2)*x)))^2) valg=2*[-(1-exp(-b(2)*x)) -b(1).*x.*exp(-b(2)*x)]'*(y-b(1)*(1-exp(-b(2)*x))); endfunction 1) [valf,b1,valg]=optimg(f,fg,[500.;0.0001 ]) 2) [valf,b1,valg]=optimg(f,fg,[500.;0.0001 ],',''br'',1e6,1e6','%eps,1e6','%eps') // Example 1 minimizes function f with optimg default values and [500;0.0001] as starting values. // Example 2 minimizes function f and [500;0.0001] as starting values, 1E6 for the maximum allowed // number of calls to the function to minimize, 1E6 for the maximum number of iterations allowed in optim, // %eps for the convergence criterion and 1E6 for the maximum number of iterations and %eps for the global // convergence criterion of the absolute mean of the gradient. | ![]() | ![]() |