# -*- coding: utf-8 -*- """ Created on Thu Dec 18 10:50:10 2014 @author: grivet Exercice 5-1e : Résolution d'une équation non-linéaire par la méthode de la sécante """ from pylab import * TOL = 1E-6 def fn(x): return x - 0.2*sin(x) - 0.5 xavder = float(input("abscisse gauche: ")) xder = float(input("abscisse droite: ")) favder = fn(xavder); fder = fn(xder) i = 1 print( 'iteration xavder x xder') while abs(xder - xavder) > TOL: x = xder - fder*(xder-xavder)/(fder-favder) f = fn(x) favder = fder; xavder = xder xder = x; fder = f print('%d \t %12.4f \t %12.4f \t %12.4f' %(i, xavder,x,xder)) i += 1 x = xder - fder*(xder-xavder)/(fder-favder) print ('\t x \t fn(x)') print( '%14.6f\t%14.6f' %(x,fn(x)))