1 import matplotlib.pyplot as plt
8 diff_div=[[0 for _ in xrange(n+1)] for _ in xrange(n+1)]
11 for j in xrange(1,n+1):
12 for i in xrange(n-j+1):
13 r = float(diff_div[i+1][j-1]-diff_div[i][j-1])/(X[i+j]-X[i])
28 def construit_et_eval_pol(X,Y,x):
31 return sum([d[i]*prod([x - X[j] for j in xrange(i)]) for i in xrange(n+1)])
35 def construit_pol(X,Y):
39 sum([d[i]*prod([x - X[j] for j in xrange(i)]) for i in xrange(n+1)])
50 p = construit_pol(X,Y)
51 Yp =[p(x) for x in XX]
52 Ypp = [construit_et_eval_pol(X,Y,x) for x in XX]
57 x=np.linspace(10,100,100)
59 plt.ylabel('temps d\'execution')
60 plt.xlabel("taille des donnees")
77 X1 = [-1+0.25*i for i in xrange(9)]
78 Y1 = [e**x for x in X1]
79 p1 = construit_pol(X1,Y1)
82 X2 = [cos(pi/2*(float(2*i+1)/9)) for i in xrange(9)]
83 Y2 = [e**x for x in X2]
84 p2 = construit_pol(X2,Y2)
88 e1 = lambda x : abs(p1(x) - e**x)
89 e2 = lambda x : abs(p2(x) - e**x)
92 l1 = [e1(-1 + 0.001*i) for i in range(2001)]
93 l2 = [e2(-1 + 0.001*i) for i in range(2001)]
95 average = lambda l : sum(l)/len(l)
97 print "l1", max(l1), average(l1)
98 print "l2", max(l2), average(l2)
101 x=np.linspace(-1,1,1000)