mirror of
https://github.com/nasa/trick.git
synced 2024-12-19 21:27:54 +00:00
Revert regula_falsi.c. Ref #995
This commit is contained in:
parent
fc7fcb175d
commit
e303b2ac9b
@ -10,9 +10,7 @@ double regula_falsi(
|
||||
double time, /* In: Current time - input (seconds) */
|
||||
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->last_error - R->error) < R->error_tol)))
|
||||
{
|
||||
@ -27,13 +25,12 @@ double regula_falsi(
|
||||
return (0.0);
|
||||
}
|
||||
}
|
||||
|
||||
if (R->error < 0.0) {
|
||||
/* Set lower bounds */
|
||||
R->x_lower = R->error;
|
||||
R->t_lower = time;
|
||||
R->lower_set = 1;
|
||||
} else if (R->error > 0.0) {
|
||||
} else if (R->error > 0.0) {
|
||||
/* Set upper bounds */
|
||||
R->x_upper = R->error;
|
||||
R->t_upper = time;
|
||||
@ -43,16 +40,15 @@ double regula_falsi(
|
||||
|
||||
/* Have now got upper and lower bounds of zero point */
|
||||
if (R->upper_set == 1 && R->lower_set == 1) {
|
||||
|
||||
/* 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;
|
||||
} else {
|
||||
double slope = (R->x_upper - R->x_lower) / (R->t_upper - R->t_lower);
|
||||
R->delta_time = -R->error / slope;
|
||||
if (R->iterations > 20) {
|
||||
else {
|
||||
R->delta_time = -R->error /
|
||||
((R->x_upper - R->x_lower) / (R->t_upper -
|
||||
R->t_lower));
|
||||
if (R->iterations > 20)
|
||||
R->delta_time = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now check for increasing or decreasing constraint */
|
||||
@ -62,25 +58,35 @@ double regula_falsi(
|
||||
R->last_tgo = R->delta_time;
|
||||
return (R->delta_time);
|
||||
case Increasing: /* Increasing slope */
|
||||
// If the slope of the error function is positive.
|
||||
if (R->t_upper > R->t_lower) {
|
||||
if (R->function_slope == Increasing) {
|
||||
R->last_error = R->error;
|
||||
R->last_tgo = R->delta_time;
|
||||
return (R->delta_time);
|
||||
} else {
|
||||
R->lower_set = 0;
|
||||
R->function_slope = Increasing;
|
||||
}
|
||||
break;
|
||||
case Decreasing: /* Decreasing slope */
|
||||
// If the slope of the error function is negative.
|
||||
if (R->t_upper < R->t_lower) {
|
||||
if (R->function_slope == Decreasing) {
|
||||
R->last_error = R->error;
|
||||
R->last_tgo = R->delta_time;
|
||||
return (R->delta_time);
|
||||
} else {
|
||||
R->upper_set = 0;
|
||||
R->function_slope = Decreasing;
|
||||
}
|
||||
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->last_tgo = BIG_TGO;
|
||||
|
||||
return (BIG_TGO);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user