No BSD License  

Highlights from
Introduction à Matlab (deuxième édition)

from Introduction à Matlab (deuxième édition) by Jean-Thierry
tous les m-fichiers relatifs à la deuxième édition de l'Introduction à Matlab

newton(fun, funprim, x0, epsi, maxiter)
function [x, ok] = newton(fun, funprim, x0, epsi, maxiter)
%  NEWTON rsolution d'une quation par la mthode de newton
%         function [x, ok] = newton(fun, funprim, x0, eps, maxiter)
%         cette fonction est purement scalaire.
%         fun      : nom de la fonction
%         funprim  : nom de la drive
%         x0       : point de dpart             (dfaut 0.0    )
%         epsi     : tolrance                   (dfaut 100*eps)
%         maxiter  : nombre maximal d'itrations (dfaut 30     )
%         ok       : 0 chec, 1 russite

if nargin < 5, maxiter = 30; end;
if nargin < 4, epsi = 100*eps; end;
if nargin < 3, x0 = 0.0; end;
if nargin < 2, error('newton demande au moins deux arguments'); end;
if ~exist(fun) | ~exist(funprim)
   error('fonction ou drive non dfinie');
end;

count = 0;
while 1
   if (count > maxiter)
      break;
   end;
   fprim = feval(funprim, x0); 
   if fprim == 0
      ok = 0;
      disp('drive nulle dans newton');
      return;
   end;
   f = feval(fun, x0);
   x = x0-f./fprim;
   if (abs(x-x0) <= epsi*abs(x0))
      ok = 1;
      return;
   end;
   x0 = x;
   count = count + 1;
end;
warning('trop d''itrations dans newton');
ok = 0;

Contact us at files@mathworks.com