Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ x,k ] = Jarratt(p, x0, tol,Max_iter)
- % STOP: |x-x0|<=tol, l<= Max_iter
- % x0- beginning approximation, k- number of iterations
- % Newton's method for findig roots of polynomial w(x), where
- % w(x)=p(1)x^n+...+p(n)x + p(n+1).
- k=0; %k- number of iterations
- t= tol+1; % iterations
- dp=polyder(p); %function derivative
- %Jarrat method
- while (abs(t)>tol)&& (k<= Max_iter),
- k=k+1;
- %calculating the value of a function for given x0 as an argument
- w0 = horner1(p,x0);
- %calculating the value of a function derivative for given x0 as an
- %argument
- dw = horner1(dp,x0);
- %checks if the value of function derivative at point x0 is equal
- %to zero, if it is the method will fail
- if dw==0,
- disp('Derivative is equal to zero!');
- return;
- end
- %calculating the value of a function derivative
- %for given x0 - 0.5*(w0/dw) as an argument
- t=w0/dw;
- d=horner1(dp,x0 - 0.5*t);
- %checks if the value of function derivative
- %at point x0 - 0.5*(w0/dw) is equal to zero
- %if it is the method will fail
- if d==0,
- disp('Derivative is equal to zero');
- return;
- end
- x = x0 - (w0/horner1(d,x0));
- x0=x;
- end
- x=x0;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement