Updated bisection root finding algorithm and test case

This commit is contained in:
2024-05-24 20:20:28 +02:00
parent cbaffbf55e
commit 53e3922654
2 changed files with 109 additions and 15 deletions

View File

@@ -54,15 +54,31 @@ begin
end;
procedure TPolynomialRootsTestCase.TestBisectionRootIsolation;
const
expRoots: array of Cardinal = (34000, 23017, 5);
var
exp: Cardinal;
a: TBigIntPolynomial;
r: Int64;
r: TIsolatingIntervals;
ri: TIsolatingInterval;
found: Boolean;
begin
// y = 3 * (x - 34000) * (x - 23017) * (x - 5) * (x^2 - 19) * (x + 112)
// = 3 * x^6 - 170730 * x^5 + 2329429920 * x^4 + 251300082690 * x^3 - 1270471872603 * x^2 + 4774763204640 * x - 24979889760000
a := TBigIntPolynomial.Create([-24979889760000, 4774763204640, -1270471872603, 251300082690, 2329429920, -170730, 3]);
r := FRootIsolation.Bisect(a);
AssertEquals(0, r);
AssertEquals(Length(expRoots), r.Count);
for exp in expRoots do
begin
found := False;
for ri in r do
if (ri.A <= exp) and (exp <= ri.B) then
begin
found := True;
Break;
end;
AssertTrue('No isolating interval for expected root ' + IntToStr(exp) + ' found.', found);
end;
end;
initialization