f<-function(x){x^3-x-1};f1<-function(x){3*x^2-1};
NIMfzero(f,f1,0)
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (f, f1, x0 = 0, num = 100, eps = 1e-05, eps1 = 1e-05)
{
a = x0
b = a - f(a)/f1(a)
i = 0
while ((abs(b - a) > eps) & (i < num)) {
a = b
b = a - f(a)/f1(a)
i = i + 1
}
print(b)
print(f(b))
if (abs(f(b)) < eps1) {
print("finding root is successful")
}
else print("finding root is fail")
}
Run the code above in your browser using DataLab