Newton-Raphson iteration

Define the function  f(x) = cos(x) - x

The equation  f(x) = 0   cannot be solved by mathematical analysis. In order to solve an equation like this we have to use a numerical method, typically on a computer. An often used method is called Newton-Raphson iteration.

The principle is this:

 

Let your program write out   x1, y1,   x2, y2,   x3, y3,   and so on.   Try with different values for the initial guess, x1, and see if it converges towards the solution.