MATLAB: 5th root with Newton-Raphson code

mathematicsMATLAB

This is a code I have created to calculate numerically the 5th root. Something is wrong.
x = 0.05;
x_old = 500;
iter = 0;
while abs(x_old-x) > 10^-3 && x ~= 0
x_old = x;
x = x - (5*x*x*x*x);
iter = iter + 1;
end

Best Answer

If n is the number whose 5th root has to be calculated:
function f = fifth_root(n)
xold=10;
for i = 1:100
xnew = xold - (xold*xold*xold*xold*xold-n)/(5*xold*xold*xold*xold);
xold=xnew;
end
f=xnew
end
Related Question