X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/cours-mesi.git/blobdiff_plain/d1778cd1db87ac86b892c6d65935e6ee1abc95a3..2db144d6141d827fa394d04e7e4ef6771c7089ee:/tps/chap2/diff_div.py?ds=inline diff --git a/tps/chap2/diff_div.py b/tps/chap2/diff_div.py index 8ac41e3..a2c7573 100644 --- a/tps/chap2/diff_div.py +++ b/tps/chap2/diff_div.py @@ -4,12 +4,12 @@ from math import * 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 @@ -34,6 +34,7 @@ def construit_et_eval_pol(X,Y,x): 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)]) @@ -41,17 +42,18 @@ def construit_pol(X,Y): -""" + 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) @@ -106,4 +108,4 @@ plt.ylabel('exp') plt.xlabel("x") plt.show() - +"""