Revert regula_falsi.c. Ref #995

This commit is contained in:
Penn, John M 047828115 2020-04-30 23:12:22 -05:00
parent fc7fcb175d
commit e303b2ac9b

View File

@ -10,9 +10,7 @@ double regula_falsi(
double time, /* In: Current time - input (seconds) */ double time, /* In: Current time - input (seconds) */
REGULA_FALSI * R) /* Inout: Regula Falsi parameters */ REGULA_FALSI * R) /* Inout: Regula Falsi parameters */
{ {
if (R->iterations > 0 &&
if (
R->iterations > 0 &&
((M_ABS(R->error) < R->error_tol) || ((M_ABS(R->error) < R->error_tol) ||
(M_ABS(R->last_error - R->error) < R->error_tol))) (M_ABS(R->last_error - R->error) < R->error_tol)))
{ {
@ -27,7 +25,6 @@ double regula_falsi(
return (0.0); return (0.0);
} }
} }
if (R->error < 0.0) { if (R->error < 0.0) {
/* Set lower bounds */ /* Set lower bounds */
R->x_lower = R->error; R->x_lower = R->error;
@ -43,17 +40,16 @@ double regula_falsi(
/* Have now got upper and lower bounds of zero point */ /* Have now got upper and lower bounds of zero point */
if (R->upper_set == 1 && R->lower_set == 1) { if (R->upper_set == 1 && R->lower_set == 1) {
/* Calculate time to error function zero point */ /* Calculate time to error function zero point */
if (M_ABS(R->error) < R->error_tol) { if (M_ABS(R->error) < R->error_tol)
R->delta_time = 0.0; R->delta_time = 0.0;
} else { else {
double slope = (R->x_upper - R->x_lower) / (R->t_upper - R->t_lower); R->delta_time = -R->error /
R->delta_time = -R->error / slope; ((R->x_upper - R->x_lower) / (R->t_upper -
if (R->iterations > 20) { R->t_lower));
if (R->iterations > 20)
R->delta_time = 0.0; R->delta_time = 0.0;
} }
}
/* Now check for increasing or decreasing constraint */ /* Now check for increasing or decreasing constraint */
switch (R->mode) { switch (R->mode) {
@ -62,25 +58,35 @@ double regula_falsi(
R->last_tgo = R->delta_time; R->last_tgo = R->delta_time;
return (R->delta_time); return (R->delta_time);
case Increasing: /* Increasing slope */ case Increasing: /* Increasing slope */
// If the slope of the error function is positive. if (R->function_slope == Increasing) {
if (R->t_upper > R->t_lower) { R->last_error = R->error;
R->last_tgo = R->delta_time;
return (R->delta_time); return (R->delta_time);
} else { } else {
R->lower_set = 0; R->lower_set = 0;
R->function_slope = Increasing;
} }
break; break;
case Decreasing: /* Decreasing slope */ case Decreasing: /* Decreasing slope */
// If the slope of the error function is negative. if (R->function_slope == Decreasing) {
if (R->t_upper < R->t_lower) { R->last_error = R->error;
R->last_tgo = R->delta_time;
return (R->delta_time); return (R->delta_time);
} else { } else {
R->upper_set = 0; R->upper_set = 0;
R->function_slope = Decreasing;
} }
break; break;
} }
R->function_slope = Any;
} else if (R->lower_set == 1) {
R->function_slope = Increasing;
} else if (R->upper_set == 1) {
R->function_slope = Decreasing;
} }
R->iterations = 0; R->iterations = 0;
R->last_tgo = BIG_TGO; R->last_tgo = BIG_TGO;
return (BIG_TGO); return (BIG_TGO);
} }