Skip to content

Commit 89e661c

Browse files
committed
Removing regula_falsa root sanity check.
With changes in recent commits the sanity check is no longer needed.
1 parent 7b1b3f1 commit 89e661c

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

source/core/math/polynomialsolver.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ static int solve_cubic (const DBL *x, DBL *y);
128128
static int solve_quartic (const DBL *x, DBL *y);
129129
static int polysolve (int order, const DBL *Coeffs, DBL *roots);
130130
static int modp (const polynomial *u, const polynomial *v, polynomial *r);
131-
static bool regula_falsa (const polynomial *sseq, DBL a, DBL b, const int np,
132-
const int atmin, const int atmax, DBL *val);
131+
static bool regula_falsa (const int order, const DBL *coef, DBL a, DBL b, DBL *val);
133132
static int sbisect (int np, const polynomial *sseq, DBL min, DBL max, int atmin, int atmax, DBL *roots);
134133
static int numchanges (int np, const polynomial *sseq, DBL a);
135134
static DBL polyeval (DBL x, int n, const DBL *Coeffs);
@@ -455,7 +454,7 @@ static int sbisect(int np, const polynomial *sseq, DBL min_value, DBL max_value,
455454
{
456455
/* first try using regula-falsa to find the root. */
457456

458-
if (regula_falsa(sseq, min_value, max_value, np, atmin, atmax, roots))
457+
if (regula_falsa(sseq->ord, sseq->coef, min_value, max_value, roots))
459458
{
460459
return(1);
461460
}
@@ -668,15 +667,14 @@ static DBL polyeval(DBL x, int n, const DBL *Coeffs)
668667
*
669668
******************************************************************************/
670669

671-
static bool regula_falsa (const polynomial *sseq, DBL a, DBL b, const int np,
672-
const int atmin, const int atmax, DBL *val)
670+
static bool regula_falsa(const int order, const DBL *coef, DBL a, DBL b, DBL *val)
673671
{
674672
bool found=false;
675673
int its;
676674
DBL fa, fb, x, fx, lfx, mid;
677675

678-
fa = polyeval(a, sseq->ord, sseq->coef);
679-
fb = polyeval(b, sseq->ord, sseq->coef);
676+
fa = polyeval(a, order, coef);
677+
fb = polyeval(b, order, coef);
680678

681679
if (fa * fb > 0.0)
682680
{
@@ -691,7 +689,7 @@ static bool regula_falsa (const polynomial *sseq, DBL a, DBL b, const int np,
691689
{
692690
x = (fb * a - fa * b) / (fb - fa);
693691

694-
fx = polyeval(x, sseq->ord, sseq->coef);
692+
fx = polyeval(x, order, coef);
695693

696694
if (fabs(mid) > RELERROR)
697695
{
@@ -786,22 +784,6 @@ static bool regula_falsa (const polynomial *sseq, DBL a, DBL b, const int np,
786784
lfx = fx;
787785
}
788786

789-
// NOTE: Code above occasionally finds root values not actual roots.
790-
// Due the fast paths at top mostly and other times unfortunate initial new x
791-
// calculations leading to iterative refinement to an invalid root value.
792-
// Oddly, the fast paths to bad roots at interval ends on the whole seem to
793-
// help root resolution given the check below tosses the the problem back to
794-
// the core bisection code.
795-
//
796-
if (found)
797-
{
798-
if ((numchanges(np, sseq, *val+SMALL_ENOUGH) != atmax) ||
799-
(numchanges(np, sseq, *val-SMALL_ENOUGH) != atmin))
800-
{
801-
found = false; // We didn't find an actual root...
802-
}
803-
}
804-
805787
return(found);
806788
}
807789

0 commit comments

Comments
 (0)