def coeffs(X,Y):
- n = len(X)-1
- diff_div=[[0 for _ in xrange(n+1)] for _ in xrange(n+1)]
- for i in xrange(n+1):
+ n = len(X)
+ diff_div=np.zeros((n,n))
+ for i in range(n):
diff_div[i][0] = Y[i]
- for j in xrange(1,n+1):
- for i in xrange(n-j+1):
+ for j in range(1,n):
+ for i in range(n-j):
r = float(diff_div[i+1][j-1]-diff_div[i][j-1])/(X[i+j]-X[i])
diff_div[i][j] = r
print diff_div
def construit_pol(X,Y):
d = coeffs(X,Y)
+ print "les coeffs sont",d
n = len(X)-1
return lambda x : \
sum([d[i]*prod([x - X[j] for j in xrange(i)]) for i in xrange(n+1)])
-"""
+
print "tp 2.1....."
X = [10,25,60]
XX= [15,40,100]
Y = [2.3, 8, 24.6]
p = construit_pol(X,Y)
+
Yp =[p(x) for x in XX]
Ypp = [construit_et_eval_pol(X,Y,x) for x in XX]
-print Yp, Ypp
+print "Yp", Yp#, Ypp
x=np.linspace(10,100,100)
plt.xlabel("x")
plt.show()
-
+"""