2nd_Sem_Bogachev/2025.05.02/dist/Krivoruchenko_SK/solve_02.c
2025-05-23 00:39:50 +03:00

37 lines
451 B
C

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