Programm is compiling
This commit is contained in:
parent
135f27f63d
commit
8e114b5c29
17 changed files with 328 additions and 90 deletions
55
2025.05.02/01Ex/solve.c
Normal file
55
2025.05.02/01Ex/solve.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include "solve.h"
|
||||
#include "status.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
status t1_solve (
|
||||
double (*f) (double),
|
||||
double a, double b,
|
||||
double eps, int m, double *x, int *m_it
|
||||
) {
|
||||
int it = 0;
|
||||
status ret = SUCCESS;
|
||||
double c = DBL_MAX, y, y_a = f(a), y_b = f(b);
|
||||
|
||||
|
||||
if (y_a * y_b >= -DBL_EPSILON)
|
||||
{
|
||||
*x = DBL_MAX;
|
||||
return MORE_ONE_ROOT;
|
||||
}
|
||||
|
||||
for (it = 0; it < m; ++it)
|
||||
{
|
||||
c = (a + b) * 0.5;
|
||||
y = f(c);
|
||||
|
||||
if (fabs(y) < eps)
|
||||
{
|
||||
ret = SUCCESS;
|
||||
break;
|
||||
} else if ((fabs(c - a) < DBL_EPSILON) || (fabs(c - b) < DBL_EPSILON))
|
||||
{
|
||||
ret = HIGH_ERROR;
|
||||
break;
|
||||
} else if (y * y_a > DBL_EPSILON)
|
||||
{
|
||||
a = c;
|
||||
y_a = y;
|
||||
} else if (y * y_b > DBL_EPSILON)
|
||||
{
|
||||
b = c;
|
||||
y_b = y;
|
||||
}
|
||||
}
|
||||
|
||||
if (it >= m)
|
||||
ret = RUN_TIME;
|
||||
|
||||
*x = c;
|
||||
*m_it = it;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue