1
{ ******************************************************************
2
Utility functions to handle roots of polynomials
3
****************************************************************** }
12
function SetRealRoots(Deg : Integer; Z : PCompVector; Tol : Float) : Integer;
13
{ ------------------------------------------------------------------
14
Set the imaginary part of a root to zero if it is less than a
15
fraction Tol of its real part. This root is therefore considered
16
real. The function returns the total number of real roots.
17
------------------------------------------------------------------ }
19
procedure SortRoots(Deg : Integer; Z : PCompVector);
20
{ ------------------------------------------------------------------
23
(1) The Nr real roots are stored in elements [1..Nr] of vector Z,
26
(2) The complex roots are stored in elements [(Nr + 1)..Deg] of
27
vector Z and are unordered.
28
------------------------------------------------------------------ }
32
function SetRealRoots(Deg : Integer; Z : PCompVector; Tol : Float) : Integer;
37
if (Z^[I].Y <> 0.0) and (Abs(Z^[I].Y) < Tol * Abs(Z^[I].X)) then
49
procedure SortRoots(Deg : Integer; Z : PCompVector);
51
I, J, K, Nr, Nc : Integer;
54
procedure Sort(X : PVector; N : Integer);
55
{ Sort vector X (insertion sort) }
60
for I := 1 to Pred(N) do
64
for J := Succ(I) to N do
75
{ Count real and complex roots }
78
if Z^[I].Y = 0.0 then Inc(Nr) else Inc(Nc);
84
{ Store real roots in R and complex roots in (X,Y) }
99
{ Sort vector R (insertion sort) }
100
if Nr > 0 then Sort(R, Nr);
102
{ Transfer real roots into elements 1..Nr }
109
{ Transfer complex roots into elements (Nr+1)..Deg }