newton w matlabie

0

czy ktos kiedys zrobil cos z metoda newtona w matlabie?
pozdrawiam

0

Znalazlem skrypt przerabiany kiedys na metodach numerycznych - moze Ci sie przyda:

function [xvect,xdif,fx,nit]=newton(x0,nmax,toll,fun,dfun)
% Newton method of the 1 variable non-linear equation root finding
%function [xvect,xdif,fx,nit]=newton(x0,nmax,toll,fun,dfun)
%OUTPUT PARAMETERS
%xvect -- x(k) sequence
%xdif -- x(k+1)-x(k) sequence
%fx -- f(x(k)) sequence
%nit -- number of iterations to convergence
%
%INPUT PARAMETERS
%x0 -- starting point
%nmax -- maximal number of iteratons
%toll -- fixed tollerance
%fun -- external function f of the x variable
%dfun -- external function - derivative of f
err=toll+1; nit=0; xvect=x0; x=x0; fx=eval(fun); xdif=[];
while (nit < nmax & err > toll),
   nit=nit+1; x=xvect(nit); dfx=eval(dfun);
   if (dfx == 0),
      err=toll*1.e-10;
      disp('Stop for vanishing dfun');
   else,
      xn=x-fx(nit)/dfx;
      err=abs(xn-x);
      xdif=[xdif; err];
      x=xn; xvect=[xvect;x];
      fx=[fx;eval(fun)];
   end;
end;
0

dzieki bardzo za odpowiedz,
ja mam problem jak rozniczkuje funkcje, i cos tam nie chce mi liczyc dlaej :(

1 użytkowników online, w tym zalogowanych: 0, gości: 1