1## Copyright (C) 2000 Ben Sapp <bsapp@lanl.gov> 2## Copyright (C) 2002 Paul Kienzle <pkienzle@gmail.com> 3## 4## This program is free software; you can redistribute it and/or modify it under 5## the terms of the GNU General Public License as published by the Free Software 6## Foundation; either version 3 of the License, or (at your option) any later 7## version. 8## 9## This program is distributed in the hope that it will be useful, but WITHOUT 10## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 12## details. 13## 14## You should have received a copy of the GNU General Public License along with 15## this program; if not, see <http://www.gnu.org/licenses/>. 16 17## -*- texinfo -*- 18## @deftypefn {Function File} {@var{xmin} =} nrm (@var{f},@var{x0}) 19## Using @var{x0} as a starting point find a minimum of the scalar 20## function @var{f}. The Newton-Raphson method is used. 21## @end deftypefn 22 23## Reference: David G Luenberger's Linear and Nonlinear Programming 24 25function x = nrm(f,x,varargin) 26 velocity = 1; 27 acceleration = 1; 28 29 h = 0.01; 30 while(abs(velocity) > 0.0001) 31 fx = feval(f,x,varargin{:}); 32 fxph = feval(f,x+h,varargin{:}); 33 fxmh = feval(f,x-h,varargin{:}); 34 velocity = (fxph - fxmh)/(2*h); 35 acceleration = (fxph - 2*fx + fxmh)/(h^2); 36 x = x - velocity/abs(acceleration); 37 endwhile 38endfunction 39