Sign in Join
Wiki copytemporary

Polynomial evaluation/fr: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Polynomial evaluation/fr

OldNewLine
1+# Introduction
2+
3+Il est souvent utile de pouvoir évaluer un polynôme pour un x donné. La méthode ci-dessous permet ce calcul à l'aide de multiplication et d'addition sans utiliser de calcul de puissance.
4+
5+# Méthode de Horner
6+
7+Ne sont évalués que des polynômes de degré 1. Par exemple, 3.x^2 + 2.x + 1, est calculé avec une factorisation astucieuse, en effet on peut aussi l'écrire ((3.x +2).x + 1).
8+
9+``` pascal
10+program PolyTest;
11+
12+type
13+ // le rang du coefficient dans le tableau est égal à son degré
14+ TDegres = 0..10;
15+ TPolynome = record
16+ Deg: TDegres;
17+ Coefs: array[TDegres] of Double;
18+ end;
19+
20+function PolyEval(const aPoly: TPolynome; X: Double): Double;
21+var
22+ i: TDegres;
23+begin
24+ with aPoly do
25+ begin
26+ Result := 0;
27+ for i := Deg downto Low(Coefs) do
28+ Result := Result * X + Coefs[i];
29+ end;
30+End;
31+
32+(* Exemples *)
33+var
34+ P: TPolynome;
35+begin
36+ P.Deg := 2;
37+ P.Coefs[2] := 3;
38+ P.Coefs[1] := 2;
39+ P.Coefs[0] := 1;
40+ (* l'idéal est d initialiser les autres coeffs avec des 0 *)
41+ WriteLn('P(',7,') = ', PolyEval(7):10:2);
42+
43+ P.Deg := 0;
44+ P.Coefs[2] := 0;
45+ P.Coefs[1] := 0;
46+ P.Coefs[0] := 1;
47+ (* l'idéal est d initialiser les autres coeffs avec des 0 *)
48+ WriteLn('P(',7,') = ', PolyEval(7):10:2);
49+End
50+```
51+
52+# Voir aussi
53+
54+\[<https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Ruffini-Horner>\| Méthode de Horner (wiki)\]
55+
56+---
57+*From the Free Pascal wiki, page "Polynomial evaluation/fr", as it stood on 2020-02-23 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history