{*********************************************** * Roots of a polynomial by Bernouilli's method * * -------------------------------------------- * * Reference: "Methodes de calcul numerique By * * Claude Nowakowski, PSI Editions, * * France, 1981" [BIBLI 04]. * * * * Pascal version by J-P Moreau * * (www.jpmoreau.fr) * * -------------------------------------------- * * SAMPLE RUN: * * * * Roots of a polynomial by Bernouilli's method * * * * Input order of polynomial: 4 * * * * Input coefficients of the polynomial: * * * * A( 0 ) = 1 * * A( 1 ) = 2 * * A( 2 ) = -13 * * A( 3 ) = -14 * * A( 4 ) = 24 * * * * ===== R O O T S ===== * * * * X1 = -4.0000 * * X2 = 3.0000 * * X3 = -2.0001 * * X4 = 1.0001 * * * ***********************************************} Program Test_Bernouilli; Uses WinCrt; Var k,nd : integer; A,Y : Array[0..25] of double; { Bernouilli's subroutine } Procedure Bernouilli; Label 5,50,100; Var k,l,n,nroot : integer; er,s,x,x1 : double; Begin writeln; writeln(' ===== R O O T S ====='); writeln; n:=nd; if ABS(A[0])<1e-12 then begin writeln(' Error: A(0) must be <> 0 !'); exit end; for k:=0 to n do A[k]:=A[k]/A[0]; nroot:=0; 5: x1:=0.0; nroot:=nroot+1; for k:=2 to n do Y[k]:=0.0; Y[1]:=1.0; for l:=1 to 50 do begin s:=0.0; for k:=1 to n do s:=s+Y[k]*A[k]; Y[0]:=-s; x:=Y[0]/Y[1]; er:=ABS(x1-x); if l