Advertisement
Guest User

Untitled

a guest
May 26th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.33 KB | None | 0 0
  1. function [ x,k ] = Jarratt(p, x0, tol,Max_iter)
  2. % STOP: |x-x0|<=tol, l<= Max_iter
  3. % x0- beginning approximation, k- number of iterations
  4. % Newton's method for findig roots of polynomial w(x), where
  5. % w(x)=p(1)x^n+...+p(n)x + p(n+1).
  6.  
  7. k=0; %k- number of iterations
  8. t= tol+1; % iterations
  9. dp=polyder(p); %function derivative
  10. %Jarrat method
  11. while (abs(t)>tol)&& (k<= Max_iter),
  12.         k=k+1;
  13.        
  14.         %calculating the value of a function for given x0 as an argument
  15.         w0 = horner1(p,x0);
  16.         %calculating the value of a function derivative for given x0 as an
  17.         %argument
  18.         dw = horner1(dp,x0);
  19.         %checks if the value of function derivative at point x0 is equal
  20.         %to zero, if it is the method will fail
  21.         if dw==0,
  22.             disp('Derivative is equal to zero!');
  23.             return;
  24.         end
  25.         %calculating the value of a function derivative
  26.         %for given x0 - 0.5*(w0/dw) as an argument
  27.         t=w0/dw;
  28.         d=horner1(dp,x0  - 0.5*t);        
  29.         %checks if the value of function derivative
  30.         %at point  x0 - 0.5*(w0/dw) is equal to zero
  31.         %if it is the method will fail
  32.         if d==0,
  33.             disp('Derivative is equal to zero');
  34.             return;
  35.         end
  36.         x = x0 - (w0/horner1(d,x0));
  37.         x0=x;
  38. end
  39. x=x0;
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement