Skip to content

Commit 7b1b3f1

Browse files
committed
Updating regula_falsa to use ray domain for the RELERROR conditions.
Previously a mix but primarily the polynomial value domain. Led to different root values at about 5-6 digits in the ray domain depending upon whether sturm chain bisection came up with the root or regula_falsa did. With update results identical out to 8-10 digits.
1 parent 15124d3 commit 7b1b3f1

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

source/core/math/polynomialsolver.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ static bool regula_falsa (const polynomial *sseq, DBL a, DBL b, const int np,
673673
{
674674
bool found=false;
675675
int its;
676-
DBL fa, fb, x, fx, lfx;
676+
DBL fa, fb, x, fx, lfx, mid;
677677

678678
fa = polyeval(a, sseq->ord, sseq->coef);
679679
fb = polyeval(b, sseq->ord, sseq->coef);
@@ -685,17 +685,19 @@ static bool regula_falsa (const polynomial *sseq, DBL a, DBL b, const int np,
685685

686686
lfx = fa;
687687

688+
mid = (a + b) / 2;
689+
688690
for (its = 0; its < MAX_ITERATIONS; its++)
689691
{
690692
x = (fb * a - fa * b) / (fb - fa);
691693

692694
fx = polyeval(x, sseq->ord, sseq->coef);
693695

694-
if (fabs(x) > RELERROR)
696+
if (fabs(mid) > RELERROR)
695697
{
696-
if (fabs(fx / x) < RELERROR)
698+
if (fabs((b - a) / mid) < RELERROR)
697699
{
698-
*val = x;
700+
*val = mid;
699701

700702
found = true;
701703

@@ -704,7 +706,15 @@ static bool regula_falsa (const polynomial *sseq, DBL a, DBL b, const int np,
704706
}
705707
else
706708
{
707-
if (fabs(fx) < RELERROR)
709+
if (fabs(b - a) < RELERROR)
710+
{
711+
*val = mid;
712+
713+
found = true;
714+
715+
break;
716+
}
717+
else if (fabs(fx) < (RELERROR/1000))
708718
{
709719
*val = x;
710720

@@ -720,6 +730,8 @@ static bool regula_falsa (const polynomial *sseq, DBL a, DBL b, const int np,
720730
{
721731
a = x;
722732

733+
mid = (a + b) / 2;
734+
723735
fa = fx;
724736

725737
if ((lfx * fx) > 0)
@@ -731,6 +743,8 @@ static bool regula_falsa (const polynomial *sseq, DBL a, DBL b, const int np,
731743
{
732744
b = x;
733745

746+
mid = (a + b) / 2;
747+
734748
fb = fx;
735749

736750
if ((lfx * fx) > 0)
@@ -745,6 +759,8 @@ static bool regula_falsa (const polynomial *sseq, DBL a, DBL b, const int np,
745759
{
746760
b = x;
747761

762+
mid = (a + b) / 2;
763+
748764
fb = fx;
749765

750766
if ((lfx * fx) > 0)
@@ -756,6 +772,8 @@ static bool regula_falsa (const polynomial *sseq, DBL a, DBL b, const int np,
756772
{
757773
a = x;
758774

775+
mid = (a + b) / 2;
776+
759777
fa = fx;
760778

761779
if ((lfx * fx) > 0)
@@ -765,17 +783,6 @@ static bool regula_falsa (const polynomial *sseq, DBL a, DBL b, const int np,
765783
}
766784
}
767785

768-
/* Check for underflow in the domain */
769-
770-
if (fabs(b-a) < RELERROR)
771-
{
772-
*val = x;
773-
774-
found = true;
775-
776-
break;
777-
}
778-
779786
lfx = fx;
780787
}
781788

0 commit comments

Comments
 (0)