Find an Error

This commit is contained in:
AZEN-SGG 2025-05-22 21:43:13 +03:00
parent 093280d5cd
commit dc3c871ae1
6 changed files with 43 additions and 37 deletions

1
.gitignore vendored
View file

@ -109,3 +109,4 @@ System Volume Information/
# Linux system files # Linux system files
lost+found/ lost+found/
.nfs*

View file

@ -1,28 +1,13 @@
#ifndef INIT_F_H #ifndef INIT_F_H
#define INIT_F_H #define INIT_F_H
int get_call_function_count (void) ; int get_call_count (void);
int get_call_derivative_count (void);
double f0 (double x); double f0 (double x);
double d0 (double x);
double f1 (double x); double f1 (double x);
double d1 (double x);
double f2 (double x); double f2 (double x);
double d2 (double x);
double f3 (double x); double f3 (double x);
double d3 (double x);
double f4 (double x); double f4 (double x);
double d4 (double x);
double f5 (double x); double f5 (double x);
double d5 (double x);
double f6 (double x); double f6 (double x);
double d6 (double x);
#endif #endif

View file

@ -26,34 +26,34 @@ double f1 (double x)
double f2 (double x) double f2 (double x)
{ {
// double x_2 = x * x; double x_2 = x * x;
cl++; cl++;
return 4 - x * x; return 4 - x_2;
} }
double f3 (double x) double f3 (double x)
{ {
//double x_2 = x * x; double x_2 = x * x;
//double x_3 = x * x_2; double x_3 = x * x_2;
cl++; cl++;
return x * x * x + 3 * x * x + 16; return x_3 + 3 * x_2 + 16;
} }
double f4 (double x) double f4 (double x)
{ {
//double x_2 = x * x; double x_2 = x * x;
//double x_4 = x_2 * x_2; double x_4 = x_2 * x_2;
cl++; cl++;
return 3 - 2 * x * x - x * x * x * x; return 3 - 2 * x_2 - x_4;
} }
double f5 (double x) double f5 (double x)
{ {
//double sq_x = sqrt(fabs(x) + 1); double sq_x = sqrt(fabs(x) + 1);
cl++; cl++;
return sqrt(fabs(x) + 1) - 2; return sq_x - 2;
} }
double f6 (double x) double f6 (double x)

View file

@ -40,6 +40,9 @@ int t3_solve (
for (it = 1; it <= m; ++it) for (it = 1; it <= m; ++it)
{ {
if (fabs(y_b) < fabs(y_a))
c = b - ((a - b) / (y_a - y_b)) * y_b;
else
c = a - ((a - b) / (y_a - y_b)) * y_a; c = a - ((a - b) / (y_a - y_b)) * y_a;
y = f(c); y = f(c);

View file

@ -40,8 +40,7 @@ int t5_solve (
return -1; return -1;
if ( if (
is_equal(y_a, y_b) || (is_equal(y_a, y_b) || is_equal(y_a, y_c)) ||
is_equal(y_a, y_c) ||
is_equal(y_b, y_c) is_equal(y_b, y_c)
) )
return -3; return -3;
@ -49,11 +48,26 @@ int t5_solve (
for (it = 1; it < m+1; ++it) for (it = 1; it < m+1; ++it)
{ {
double *temp_pnt = 0, *inner_max_pnt; double *temp_pnt = 0, *inner_max_pnt;
const double angle = (c - a) / (y_c - y_a); double angle, x_new, y_new;
const double x_new = a -
if (is_equal(y_a, y_b))
return -3;
else if (is_equal(y_a, y_c))
return -3;
else if (is_equal(y_b, y_c))
return -3;
if (
(is_equal(y_a, y_b) || is_equal(y_a, y_c)) ||
is_equal(y_b, y_c)
)
return -3;
angle = (c - a) / (y_c - y_a);
x_new = a -
angle * y_a + angle * y_a +
((((b - c) / (y_b - y_c)) - angle) / (y_b - y_a)) * y_a * y_c; ((((b - c) / (y_b - y_c)) - angle) / (y_b - y_a)) * y_a * y_c;
const double y_new = f(x_new); y_new = f(x_new);
if (is_eps(y_new, eps)) if (is_eps(y_new, eps))
{ {
@ -62,15 +76,15 @@ int t5_solve (
} }
if ( if (
is_equal(x_new, a) || (is_equal(x_new, a) ||
is_equal(x_new, c) || is_equal(x_new, c)) ||
is_equal(x_new, b) is_equal(x_new, b)
) )
return -1; return -1;
if ( if (
is_equal(y_new, y_a) || (is_equal(y_new, y_a) ||
is_equal(y_new, y_c) || is_equal(y_new, y_c)) ||
is_equal(y_new, y_b) is_equal(y_new, y_b)
) )
return -3; return -3;

View file

@ -3,6 +3,9 @@
#include <math.h> #include <math.h>
#include <float.h> #include <float.h>
#include <stdio.h>
#define EPS 1e-16
static inline double * fpmax (double *pa, double *pb, double fa, double fb, double *max_f_p) static inline double * fpmax (double *pa, double *pb, double fa, double fb, double *max_f_p)
{ {
@ -34,7 +37,7 @@ static inline int is_equal (const double a, const double b)
{ {
double diff = a - b; double diff = a - b;
double max_val = (a > b) ? a : b; double max_val = (a > b) ? a : b;
return ((diff < 0) ? -diff : diff) < (DBL_EPSILON * max_val); return (fabs(diff) < (EPS * fabs(max_val)));
} }
static inline int is_null (const double a) static inline int is_null (const double a)