Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| teaching:progappchim:polynomes-6 [2012/11/09 08:27] – villersd | teaching:progappchim:polynomes-6 [2017/02/28 10:01] (Version actuelle) – villersd | ||
|---|---|---|---|
| Ligne 16: | Ligne 16: | ||
| Nous avons donc 4 multiplications à effectuer, et pas 4 + 3 + 2 + 1 multiplications en absence de réarrangement. | Nous avons donc 4 multiplications à effectuer, et pas 4 + 3 + 2 + 1 multiplications en absence de réarrangement. | ||
| - | Cette façon d' | + | Cette façon d' |
| - | <sxh python; title : poly06-horner.py> | + | <note tip> |
| - | # | + | |
| + | < | ||
| + | #!/usr/bin/env python | ||
| # -*- coding: UTF-8 -*- | # -*- coding: UTF-8 -*- | ||
| - | """ | + | """ |
| + | écriture d'un programme pour évaluer | ||
| des polynomes | des polynomes | ||
| """ | """ | ||
| Ligne 27: | Ligne 30: | ||
| def polyeval(x, | def polyeval(x, | ||
| - | """ | + | """ |
| + | | ||
| cf. http:// | cf. http:// | ||
| """ | """ | ||
| - | n=len(a)-1 | + | n = len(a) - 1 |
| - | p=a[n] | + | p = 0. |
| - | for i in range(n-1,-1,-1): | + | for i in range(n, |
| - | p=p*x+a[i] | + | p = p * x + a[i] |
| return p | return p | ||
| | | ||
| - | x=2. # x particulier | + | x = 2. # x particulier |
| - | a=[1, | + | a = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] # coefficients particuliers |
| - | print polyeval(x, | + | print(polyeval(x, |
| - | varx=0.5 | + | varx = 0.5 |
| - | varcoef=[1., | + | varcoef = [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.] |
| - | print polyeval(varx, | + | print(polyeval(varx, |
| for j in range(0, | for j in range(0, | ||
| - | vax=float(j)*0.1 | + | vax = float(j) * 0.1 |
| - | rep=sin(polyeval(vax, | + | rep = sin(polyeval(vax, |
| - | print rep | + | print(rep) |
| - | </sxh> | + | </code> |
| - | Écrivons à présent d' | + | Écrivons à présent d' |
| - la fonction de multiplication d'un polynôme pas un scalaire | - la fonction de multiplication d'un polynôme pas un scalaire | ||
| - la fonction d' | - la fonction d' | ||