Sign in Join
Wiki copytemporary

Revision 1 of 1, by Trev on 2-23-2020. The page as it is now.

Polynomial evaluation/fr

Introduction

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.

Méthode de Horner

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).

pascal
program PolyTest;

type 
  // le rang du coefficient dans le tableau est égal à son degré
  TDegres = 0..10; 
  TPolynome = record 
    Deg: TDegres; 
    Coefs: array[TDegres] of Double; 
  end;

function PolyEval(const aPoly: TPolynome; X: Double): Double; 
var 
  i: TDegres; 
begin 
  with aPoly do 
  begin 
    Result := 0; 
    for i := Deg downto Low(Coefs) do 
      Result := Result * X + Coefs[i]; 
  end; 
End; 
  
(* Exemples *) 
var 
  P: TPolynome; 
begin 
  P.Deg := 2; 
  P.Coefs[2] := 3; 
  P.Coefs[1] := 2; 
  P.Coefs[0] := 1;   
  (* l'idéal est d initialiser  les autres coeffs avec des 0 *) 
  WriteLn('P(',7,') = ', PolyEval(7):10:2);  
  
  P.Deg := 0; 
  P.Coefs[2] := 0; 
  P.Coefs[1] := 0; 
  P.Coefs[0] := 1;   
  (* l'idéal est d initialiser  les autres coeffs avec des 0 *) 
  WriteLn('P(',7,') = ', PolyEval(7):10:2);  
End

Voir aussi

[https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Ruffini-Horner| Méthode de Horner (wiki)]


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.