mirror of
https://github.com/nasa/trick.git
synced 2024-12-20 05:37:55 +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) */
|
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,13 +25,12 @@ 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;
|
||||||
R->t_lower = time;
|
R->t_lower = time;
|
||||||
R->lower_set = 1;
|
R->lower_set = 1;
|
||||||
} else if (R->error > 0.0) {
|
} else if (R->error > 0.0) {
|
||||||
/* Set upper bounds */
|
/* Set upper bounds */
|
||||||
R->x_upper = R->error;
|
R->x_upper = R->error;
|
||||||
R->t_upper = time;
|
R->t_upper = time;
|
||||||
@ -43,16 +40,15 @@ 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 */
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user