1 import matplotlib.pyplot as plt
8 diff_div=np.zeros((n,n))
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):
37 print "les coeffs sont",d
40 sum([d[i]*prod([x - X[j] for j in xrange(i)]) for i in xrange(n+1)])
51 p = construit_pol(X,Y)
53 Yp =[p(x) for x in XX]
54 Ypp = [construit_et_eval_pol(X,Y,x) for x in XX]
59 x=np.linspace(10,100,100)
61 plt.ylabel('temps d\'execution')
62 plt.xlabel("taille des donnees")
79 X1 = [-1+0.25*i for i in xrange(9)]
80 Y1 = [e**x for x in X1]
81 p1 = construit_pol(X1,Y1)
84 X2 = [cos(pi/2*(float(2*i+1)/9)) for i in xrange(9)]
85 Y2 = [e**x for x in X2]
86 p2 = construit_pol(X2,Y2)
90 e1 = lambda x : abs(p1(x) - e**x)
91 e2 = lambda x : abs(p2(x) - e**x)
94 l1 = [e1(-1 + 0.001*i) for i in range(2001)]
95 l2 = [e2(-1 + 0.001*i) for i in range(2001)]
97 average = lambda l : sum(l)/len(l)
99 print "l1", max(l1), average(l1)
100 print "l2", max(l2), average(l2)
103 x=np.linspace(-1,1,1000)