2nd_Sem_Bogachev/2025.05.02/07Ex/solve.c
2025-05-01 19:05:23 +03:00

33 lines
395 B
C

#include "solve.h"
#include <math.h>
#include <float.h>
int t7_solve (
double (*f) (double),
double x_0, double eps,
int m, double *x
) {
int it = 0;
double y = f(x_0);
if (fabs(y - x_0) - eps < DBL_EPSILON)
{
*x = x_0;
return 1;
}
for (it = 0; it < m; ++it)
{
x_0 = y;
y = f(x_0);
if (fabs(y - x_0) - eps < DBL_EPSILON)
break;
}
*x = x_0;
return it;
}