...calculate the value of a polynomial at a given point?
|
Autor:
Loïs Bégué |
[ Print tip
] | | |
// Simultaneous evaluation of a given polynomial and its first derivative at a given point
// Simultane Berechnung des Wertes eines Polynoms n-ten Grades und seiner Ableitung
type
TPolynomArray = array of Double;
procedure Horner(Polynom: TPolynomArray; X: Extended; var FX, derivation: Extended);
var
i: Integer;
H: Integer;
begin
H := High(Polynom);
FX := Polynom[H];
derivation := 0.0;
for i := H - 1 downto 0 do
begin
derivation := derivation * X + FX;
FX := FX * X + Polynom[i];
end;
end;
{Beispiel / Sample code }
procedure TForm1.Button1Click(Sender: TObject);
var
X, FX, derivation: Extended;
begin
(* Horner's scheme give an algorithm for the simultaneous evaluation
of a given polynomial and its first derivative at a given point *)
(* Hornerschema zur Berechnung eines Polynoms n-ten Grades an einem
bestimmten Punkt *)
(* f(x) = 3 x^5 + 4 x^4 + 13 x^3 - 59 x^2 + 19 x - 97 *)
X := 2.5;
Horner(VarArrayOf([-97, 19, - 59, 13, 4, 3]), X, FX, derivation);
ShowMessage(Format('x = %n'#13#10'f(x) = %n'#13#10'f''(x) = %n', [X, FX, derivation]));
end;
|