Write a function that implements Newton methods. The function \(F\), its derivative, and the initial value \(y_0\) is passed in as arguments together with a tolerance \(\epsilon\). The method should return the first element \(y_n\) in the sequence

\[y_{n+1} = y_n - \frac{F(y_n)}{F'(y_n)} \]

which satisfies \(|F(y_n)|<\epsilon\).

To avoid an infinite loop in case Newton's method does not converge stop the method after computing the first \(N\) iterates. In addition to \(y_n\) also return the number \(n\) of iterations performed. So convergence of the method can be tested by checking \(n<N\).

Matlab |
Python |
---|---|

function [y, n] = newton (F, DF, y0, eps,N) % your code to compute y and n end |
def newton (F, DF, y0, eps,N): # your code to compute y and n return y, n |

]]>