Laguerre's Method catastrophic cancellation

2 views (last 30 days)
I am trying to find the roots of f(x) = x^5 - 9x^4 -x^3 +17x^2 -8x -8 , using Laguerre's method.
I wrote a general code to run different fixed point methods,
%%%%%%%%%%%
function [c, k] = fixd(g,a, tol)
k = 1;
x = zeros(1,1,'double');
x = a;
next=zeros(1,1,'double');
MAX = 10000;
next = g(x);
while k < MAX && abs(next - x) > tol
x = next;
next = g(x);
k = k + 1;
end
c = x;
end
%%%%%%%%%%%
and codes for f(x), f'(x), and f''(x) :
%%% f(x) %%%
function val = fun3(x)
val = x*(x*(x*(x*(x - 9)-1)+17)-8)-8;
end
%%%%%%%%%%%%%
%%% f'(x) %%%
function val = fun3prime(x)
val = x*(x*(x*(5*x-36)-3)+34)-8;
end
%%%%%%%%%%%%%
%%% f''(x) %%%
function val = fun3dprime(x)
val = x*(x*(20*x - 108) - 6) + 34 ;
end
%%%%%%%%%%%%%%
And here is the code I wrote for calculating the value for a in Laguerre's method:
%%% Laguerre's iterative function %%%
function [c] = laguerrefunct(x)
a=zeros(1,1,'double');
G=zeros(1,1,'double');
H=zeros(1,1,'double');
c=zeros(1,1,'double');
G = fun3prime(x) / fun3(x) ;
H = (G*G) - (fun3dprime(x) / fun3(x)) ;
if G + sqrt(4*(5*H - G*G)) > G - sqrt(4*(5*H - G*G))
a = G + sqrt(4*(5*H - G*G));
else
a = G - sqrt(4*(5*H - G*G));
end
c = x - a;
end
%%%%%%%%%%%%%%%%%%
This diverges for values close to my roots. I am thinking the problem is catastrophic cancellation. Any help?

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!