NDcost - generic external for optim computing gradient using finite differences
This function can be used as an external for optim to minimize problem where gradient is too complicated to be programmed. only the function fun which computes the criterion is required.
This function should be used as follow: [f,xopt,gopt]=optim(list(CDcost,fun,p1,...pn),x0,...)
//function to minimize function f=rosenbrock(x,varagin) p=varargin(1) f=1+sum( p*(x(2:$)-x(1:$-1)^2)^2 + (1-x(2:$))^2) endfunction x0=[1;2;3;4]; [f,xopt,gopt]=optim(list(NDcost,rosenbrock,200),x0)