# -*- coding: utf-8 -*-
"""
Created on Sat Apr 12 14:56:01 2014

@author: dconduche
"""

"""Calcul de la dérivée"""

def derive(f, x0, h):
    return (f(x0+h) - f(x0-h)) / (2*h)

"""Méthode de Newton"""

def methode_newton(f, x, n):
    for i in range(n):
        x = x-f(x)/derive(f,x,0.0001)
    return x

# Retourne un float,
# approchant la solution de f(x) = 0 (enfin si f a de bonnes propriétés).

#Tests

print(methode_newton(lambda x : x**2-2,2,100))
