This is an open method and it comes from the Newton- Raphson Method used to find a root of a function, or the value where it crosses the x axis.
You will need to provide an initial value x0, a second value x1 a tolerance to error, the number of iterations wanted, and the f(x) function.
The code works as follows:
- The x0 and the x1 are evaluated into f(x0) and f(x1).
- Then, a xn value is found using the formula x1-f(x1)*(x1-x0)/(f(x1)-f(x0)=xn.
- This xn is evaluated into f(xn), and now it becomes the new x1, while the previous x1 becomes the new x0.
- It will continue doing the same, creating new x0 and x1s, evaluating xn, checking for how close it is to zero in the y axis, till the error<tolerance, then it has found a root.