whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

40 Visitors Online


 
...calculate the value of a polynomial at a given point?
Autor: Loïs Bégué
[ Print tip ]  

Tip Rating (3):  
     


// 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 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;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners