I'm trying to implement the Newton-Raphson method in Scilab where the input must be a root point of the equation already established inside the function. However after doing the derivative of the function and inputting the root, I get division by zero. Any idea why the derivative is equal to zero when inputting 2 as the root point?
function y = fun(x)
y = -0.01 + (1/1+ x^2);
endfunction
function y= dfun(x)
y = (-2.00*x) / (1+x^2)^2
endfunction
No = 0;
x1 = 0;
x0 = input('Diga el valor inicial: ');
error = 1e^-10;
while (abs(fun(x0)) > error)
x1 = x0 - fun (x0) / dfun(x0);
x0 = x1;
No = No + 1;
end;
disp(x1, "Valor: ");
disp(No, "Numero de iteraciones: ")
ERROR HERE
Diga el valor inicial: 2
x1 = x0 - fun (x0) / dfun(x0);
!--error 27
Division by zero...
at line 12 of exec file called by :
exec('C:\Users\Silvestrini\Documents\Raphson.sci', -1)