From dc3c871ae1dadffc23464cdc0243f4a1fcd15d51 Mon Sep 17 00:00:00 2001 From: AZEN-SGG Date: Thu, 22 May 2025 21:43:13 +0300 Subject: [PATCH] Find an Error --- .gitignore | 1 + 2025.05.02/02Ex/init_f.h | 17 +---------------- 2025.05.02/03Ex/init_f.c | 20 ++++++++++---------- 2025.05.02/03Ex/solve.c | 5 ++++- 2025.05.02/05Ex/solve.c | 32 +++++++++++++++++++++++--------- 2025.05.02/05Ex/solve.h | 5 ++++- 6 files changed, 43 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 672039c..6cdc4e9 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,4 @@ System Volume Information/ # Linux system files lost+found/ +.nfs* diff --git a/2025.05.02/02Ex/init_f.h b/2025.05.02/02Ex/init_f.h index 9bba4eb..ee5e8e8 100644 --- a/2025.05.02/02Ex/init_f.h +++ b/2025.05.02/02Ex/init_f.h @@ -1,28 +1,13 @@ #ifndef INIT_F_H #define INIT_F_H -int get_call_function_count (void) ; -int get_call_derivative_count (void); - +int get_call_count (void); double f0 (double x); -double d0 (double x); - double f1 (double x); -double d1 (double x); - double f2 (double x); -double d2 (double x); - double f3 (double x); -double d3 (double x); - double f4 (double x); -double d4 (double x); - double f5 (double x); -double d5 (double x); - double f6 (double x); -double d6 (double x); #endif diff --git a/2025.05.02/03Ex/init_f.c b/2025.05.02/03Ex/init_f.c index 94fbd70..7314dd0 100644 --- a/2025.05.02/03Ex/init_f.c +++ b/2025.05.02/03Ex/init_f.c @@ -26,34 +26,34 @@ double f1 (double x) double f2 (double x) { - // double x_2 = x * x; + double x_2 = x * x; cl++; - return 4 - x * x; + return 4 - x_2; } double f3 (double x) { - //double x_2 = x * x; - //double x_3 = x * x_2; + double x_2 = x * x; + double x_3 = x * x_2; cl++; - return x * x * x + 3 * x * x + 16; + return x_3 + 3 * x_2 + 16; } double f4 (double x) { - //double x_2 = x * x; - //double x_4 = x_2 * x_2; + double x_2 = x * x; + double x_4 = x_2 * x_2; cl++; - return 3 - 2 * x * x - x * x * x * x; + return 3 - 2 * x_2 - x_4; } double f5 (double x) { - //double sq_x = sqrt(fabs(x) + 1); + double sq_x = sqrt(fabs(x) + 1); cl++; - return sqrt(fabs(x) + 1) - 2; + return sq_x - 2; } double f6 (double x) diff --git a/2025.05.02/03Ex/solve.c b/2025.05.02/03Ex/solve.c index cb6a09f..e9c6ad6 100644 --- a/2025.05.02/03Ex/solve.c +++ b/2025.05.02/03Ex/solve.c @@ -40,7 +40,10 @@ int t3_solve ( for (it = 1; it <= m; ++it) { - c = a - ((a - b) / (y_a - y_b)) * y_a; + 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; y = f(c); memcpy(&bits, &y, sizeof(bits)); diff --git a/2025.05.02/05Ex/solve.c b/2025.05.02/05Ex/solve.c index 0370646..75c9a30 100644 --- a/2025.05.02/05Ex/solve.c +++ b/2025.05.02/05Ex/solve.c @@ -40,8 +40,7 @@ int t5_solve ( return -1; if ( - is_equal(y_a, y_b) || - is_equal(y_a, y_c) || + (is_equal(y_a, y_b) || is_equal(y_a, y_c)) || is_equal(y_b, y_c) ) return -3; @@ -49,11 +48,26 @@ int t5_solve ( for (it = 1; it < m+1; ++it) { double *temp_pnt = 0, *inner_max_pnt; - const double angle = (c - a) / (y_c - y_a); - const double x_new = a - + double angle, x_new, y_new; + + 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 + ((((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)) { @@ -62,15 +76,15 @@ int t5_solve ( } if ( - is_equal(x_new, a) || - is_equal(x_new, c) || + (is_equal(x_new, a) || + is_equal(x_new, c)) || is_equal(x_new, b) ) return -1; if ( - is_equal(y_new, y_a) || - is_equal(y_new, y_c) || + (is_equal(y_new, y_a) || + is_equal(y_new, y_c)) || is_equal(y_new, y_b) ) return -3; diff --git a/2025.05.02/05Ex/solve.h b/2025.05.02/05Ex/solve.h index 1ff07f7..cb748bd 100644 --- a/2025.05.02/05Ex/solve.h +++ b/2025.05.02/05Ex/solve.h @@ -3,6 +3,9 @@ #include #include +#include + +#define EPS 1e-16 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 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)