From 8e6617686b9ebfeedf7cf5d9d97ced1bddafbd1a Mon Sep 17 00:00:00 2001 From: AZEN-SGG Date: Wed, 7 May 2025 18:06:47 +0300 Subject: [PATCH] Absolutly wrong done Task 5 --- 2025.05.02/05Ex/Makefile | 42 ++++++++++++++ 2025.05.02/05Ex/init_f.c | 66 ++++++++++++++++++++++ 2025.05.02/05Ex/init_f.h | 14 +++++ 2025.05.02/05Ex/main.c | 49 ++++++++++++++++ 2025.05.02/05Ex/solve.c | 117 +++++++++++++++++++++++++++++++++++++++ 2025.05.02/05Ex/solve.h | 56 +++++++++++++++++++ 2025.05.02/06Ex/Makefile | 42 ++++++++++++++ 2025.05.02/06Ex/init_f.c | 61 ++++++++++++++++++++ 2025.05.02/06Ex/init_f.h | 13 +++++ 2025.05.02/06Ex/main.c | 49 ++++++++++++++++ 2025.05.02/06Ex/solve.c | 103 ++++++++++++++++++++++++++++++++++ 2025.05.02/06Ex/solve.h | 10 ++++ 2025.05.09/04Ex/Makefile | 42 ++++++++++++++ 2025.05.09/04Ex/init_f.c | 61 ++++++++++++++++++++ 2025.05.09/04Ex/init_f.h | 13 +++++ 2025.05.09/04Ex/main.c | 46 +++++++++++++++ 2025.05.09/04Ex/solve.c | 14 +++++ 2025.05.09/04Ex/solve.h | 9 +++ 18 files changed, 807 insertions(+) create mode 100644 2025.05.02/05Ex/Makefile create mode 100644 2025.05.02/05Ex/init_f.c create mode 100644 2025.05.02/05Ex/init_f.h create mode 100644 2025.05.02/05Ex/main.c create mode 100644 2025.05.02/05Ex/solve.c create mode 100644 2025.05.02/05Ex/solve.h create mode 100644 2025.05.02/06Ex/Makefile create mode 100644 2025.05.02/06Ex/init_f.c create mode 100644 2025.05.02/06Ex/init_f.h create mode 100644 2025.05.02/06Ex/main.c create mode 100644 2025.05.02/06Ex/solve.c create mode 100644 2025.05.02/06Ex/solve.h create mode 100644 2025.05.09/04Ex/Makefile create mode 100644 2025.05.09/04Ex/init_f.c create mode 100644 2025.05.09/04Ex/init_f.h create mode 100644 2025.05.09/04Ex/main.c create mode 100644 2025.05.09/04Ex/solve.c create mode 100644 2025.05.09/04Ex/solve.h diff --git a/2025.05.02/05Ex/Makefile b/2025.05.02/05Ex/Makefile new file mode 100644 index 0000000..144ea6d --- /dev/null +++ b/2025.05.02/05Ex/Makefile @@ -0,0 +1,42 @@ +WFLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused \ +-Wempty-body -Wlogical-op -Wold-style-declaration -Wmissing-parameter-type \ +-Wignored-qualifiers -Winit-self -Wshadow -Wtype-limits \ +-Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 \ +-Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs \ +-Wmissing-prototypes -Wmissing-declarations -Wold-style-definition \ +-Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal \ +-Wwrite-strings -Wno-long-long -std=gnu99 -Wstrict-prototypes \ +-Wmissing-field-initializers -Wpointer-sign + +LDFLAGS = -std=gnu99 -mfpmath=sse -O3 +LDLIBS = -lm + +ifeq ($(OS),Windows_NT) + EXE = exe + CLEAN = del + LDLIBS += -lssp +else + EXE = out + CLEAN = rm -f +endif + +TARGET = a05.$(EXE) +OBJ = main.o solve.o init_f.o + +%.o: %.c + gcc $(WFLAGS) $(LDFLAGS) -c $< -o $@ + +$(TARGET): $(OBJ) + gcc $^ -o $@ $(LDLIBS) + +# Отладочная сборка (gdb) +gdb: LDFLAGS = -std=gnu99 -mfpmath=sse -g -O0 +gdb: clean $(TARGET) + +# Профилировочная сборка (gprof) +prof: LDFLAGS += -pg +prof: LDLIBS += -pg +prof: clean $(TARGET) + +clean: + $(CLEAN) *.o *$(EXE) diff --git a/2025.05.02/05Ex/init_f.c b/2025.05.02/05Ex/init_f.c new file mode 100644 index 0000000..aeee206 --- /dev/null +++ b/2025.05.02/05Ex/init_f.c @@ -0,0 +1,66 @@ +#include "init_f.h" + +#include + + +static int cl = 0; + +int get_call_count (void) +{ + return cl; +} + +double f0 (double x) +{ + cl++; + (void)x; + + return 1; +} + +double f1 (double x) +{ + cl++; + return (x * 1e-100) - 1.0; +} + +double f2 (double x) +{ + cl++; + return 4 - x * x; +} + +double f3 (double x) +{ + double x_2 = x * x; + cl++; + + return x * x_2 + 3 * x_2 + 16; +} + +double f4 (double x) +{ + double x_2 = x * x; + cl++; + + return 3 - 2 * x_2 - x_2 * x_2; +} + +double f5 (double x) +{ + cl++; + return sqrt(fabs(x) + 1) - 2; +} + +double f6 (double x) +{ + cl++; + return sqrt(sqrt(fabs(x) + 1) + 1) - 2; +} + +double f7 (double x) +{ + cl++; + return tanh(x) - x * 0.5; +} + diff --git a/2025.05.02/05Ex/init_f.h b/2025.05.02/05Ex/init_f.h new file mode 100644 index 0000000..c15260a --- /dev/null +++ b/2025.05.02/05Ex/init_f.h @@ -0,0 +1,14 @@ +#ifndef INIT_F_H +#define INIT_F_H + +int get_call_count (void); +double f0 (double x); +double f1 (double x); +double f2 (double x); +double f3 (double x); +double f4 (double x); +double f5 (double x); +double f6 (double x); +double f7 (double x); + +#endif diff --git a/2025.05.02/05Ex/main.c b/2025.05.02/05Ex/main.c new file mode 100644 index 0000000..0b6d7bc --- /dev/null +++ b/2025.05.02/05Ex/main.c @@ -0,0 +1,49 @@ +#include +#include +#include + +#include "init_f.h" +#include "solve.h" + +/* ./a.out a b eps M k */ +int main(int argc, char *argv[]) +{ + double t, a, b, eps, x = 0; + int m, k, cl, it, task = 5; + + double (*f) (double); + double (*f_lst[]) (double) = {f0, f1, f2, f3, f4, f5, f6, f7}; //TODO: Rem f7 + int len_f = sizeof(f_lst) / sizeof(f_lst[0]); + + if ( + !((argc == 6) && + sscanf(argv[1], "%lf", &a) == 1 && + sscanf(argv[2], "%lf", &b) == 1 && + (a <= b) && + (sscanf(argv[3], "%lf", &eps) == 1 && (eps >= 0)) && + ((sscanf(argv[4], "%d", &m) == 1) && m > 0) && + ((sscanf(argv[5], "%d", &k) == 1) && ((0 <= k) && (k <= len_f)))) + ) { + fprintf(stderr, "Usage: %s a b eps M k\n", argv[0]); + return -1; + } + + f = f_lst[k]; + + t = clock(); + it = t5_solve(f, a, b, eps, m, &x); + t = (clock() - t) / CLOCKS_PER_SEC; + + cl = get_call_count(); + + if (it < 0) + { + fprintf(stdout, "%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], task, cl, t); + return -2; + } else + { + printf("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], task, x, f(x), it, cl, t); + return 0; + } +} + diff --git a/2025.05.02/05Ex/solve.c b/2025.05.02/05Ex/solve.c new file mode 100644 index 0000000..c595000 --- /dev/null +++ b/2025.05.02/05Ex/solve.c @@ -0,0 +1,117 @@ +#include "solve.h" + +#include +#include +#include +#include +#include + +int t5_solve ( + double (*f) (double), + double a, double b, + double eps, int m, double *x +) { + int it; + double c = (a + b) / 2; + + double y_a = f(a); + double y_c = f(c); + double y_b = f(b); + + if (is_null(y_a)) + return 1; + else if (is_null(y_b)) + return 1; + else if (is_null(y_c)) + return 1; + + if (is_equal(a, b)) + return -1; + else if (is_equal(a, c)) + return -1; + else if (is_equal(b, c)) + return -1; + + for (it = 1; it < m+1; ++it) + { + double x_new, y_new, *temp_pnt = 0, *inner_max_pnt; + const double m_1 = (y_c - y_a) / (c - a); + const double m_2 = (y_b - y_c) / (b - c); + + const double A = (m_2 - m_1) / (b - a); + const double B = m_1 - A * (a + c); + const double C = y_a - a * m_1 + A * a * c; + + const double D = B * B - 4 * A * C; + + if (is_null(A)) + return -3; + else if (D < -DBL_EPSILON) + return -1; + else if (D > DBL_EPSILON) + { + const double sqrt_D = sqrt(D); + const double inv_A = 1./(2 * A); + + double x_1 = (-B + sqrt_D) * inv_A; + double x_2 = (-B - sqrt_D) * inv_A; + + double y_x_1 = f(x_1); + double y_x_2 = f(x_2); + + if (is_eps(y_x_1, eps)) + { + *x = x_1; + return it; + } else if (is_eps(y_x_2, eps)) + { + *x = x_2; + return it; + } else if (y_x_2 - y_x_1 > DBL_EPSILON) + { + x_new = x_1; + y_new = y_x_1; + } else + { + x_new = x_2; + y_new = y_x_2; + } + } else + { + double x_1 = -B / (2 * A); + double y_x_1 = f(x_1); + + if (is_eps(y_x_1, eps)) + { + *x = x_1; + return it; + } + + x_new = x_1; + y_new = y_x_1; + } + + if ( + is_equal(x_new, a) || + is_equal(x_new, c) || + is_equal(x_new, b) + ) + return -1; + + inner_max_pnt = fp_abs_max(&c, &b, &y_c, &y_b, &temp_pnt); + *fp_abs_max(&a, inner_max_pnt, &y_a, temp_pnt, &temp_pnt) = x_new; + if (fabs(y_new) - fabs(*temp_pnt) > DBL_EPSILON) + return -4; + *temp_pnt = y_new; + } + + if (it > m) + return -2; + else + { + double temp = 0, *temp_x_pnt = fpmax(&c, &b, -y_c, -y_b, &temp); + *x = *fpmax(&a, temp_x_pnt, -y_a, temp, &temp); + return it; + } +} + diff --git a/2025.05.02/05Ex/solve.h b/2025.05.02/05Ex/solve.h new file mode 100644 index 0000000..1ff07f7 --- /dev/null +++ b/2025.05.02/05Ex/solve.h @@ -0,0 +1,56 @@ +#ifndef SOLVE_H +#define SOLVE_H + +#include +#include + +static inline double * fpmax (double *pa, double *pb, double fa, double fb, double *max_f_p) +{ + if ((fa - fb) > DBL_EPSILON) + { + *max_f_p = fa; + return pa; + } else + { + *max_f_p = fb; + return pb; + } +} + +static inline double * fp_abs_max (double *pa, double *pb, double *fa, double *fb, double **max_f_p) +{ + if ((fabs(*fa) - fabs(*fb)) > DBL_EPSILON) + { + *max_f_p = fa; + return pa; + } else + { + *max_f_p = fb; + return pb; + } +} + +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); +} + +static inline int is_null (const double a) +{ + return ((a < 0) ? -a : a) < DBL_EPSILON; +} + +static inline int is_eps (const double a, const double eps) +{ + return (((a < 0) ? -a : a) - eps) < DBL_EPSILON; +} + +int t5_solve ( + double (*f) (double), + double a, double b, + double eps, int m, double *x + ); + +#endif diff --git a/2025.05.02/06Ex/Makefile b/2025.05.02/06Ex/Makefile new file mode 100644 index 0000000..c209389 --- /dev/null +++ b/2025.05.02/06Ex/Makefile @@ -0,0 +1,42 @@ +WFLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused \ +-Wempty-body -Wlogical-op -Wold-style-declaration -Wmissing-parameter-type \ +-Wignored-qualifiers -Winit-self -Wshadow -Wtype-limits \ +-Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 \ +-Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs \ +-Wmissing-prototypes -Wmissing-declarations -Wold-style-definition \ +-Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal \ +-Wwrite-strings -Wno-long-long -std=gnu99 -Wstrict-prototypes \ +-Wmissing-field-initializers -Wpointer-sign + +LDFLAGS = -std=gnu99 -mfpmath=sse -O3 +LDLIBS = -lm + +ifeq ($(OS),Windows_NT) + EXE = exe + CLEAN = del + LDLIBS += -lssp +else + EXE = out + CLEAN = rm -f +endif + +TARGET = a06.$(EXE) +OBJ = main.o solve.o init_f.o + +%.o: %.c + gcc $(WFLAGS) $(LDFLAGS) -c $< -o $@ + +$(TARGET): $(OBJ) + gcc $^ -o $@ $(LDLIBS) + +# Отладочная сборка (gdb) +gdb: LDFLAGS = -std=gnu99 -mfpmath=sse -g -O0 +gdb: clean $(TARGET) + +# Профилировочная сборка (gprof) +prof: LDFLAGS += -pg +prof: LDLIBS += -pg +prof: clean $(TARGET) + +clean: + $(CLEAN) *.o *$(EXE) diff --git a/2025.05.02/06Ex/init_f.c b/2025.05.02/06Ex/init_f.c new file mode 100644 index 0000000..22eb5ea --- /dev/null +++ b/2025.05.02/06Ex/init_f.c @@ -0,0 +1,61 @@ +#include "init_f.h" + +#include + + +static int cl = 0; + +int get_call_count (void) +{ + return cl; +} + +double f0 (double x) +{ + cl++; + (void)x; + + return 1; +} + +double f1 (double x) +{ + cl++; + return (x * 1e-100) - 1.0; +} + +double f2 (double x) +{ + cl++; + return 4 - x * x; +} + +double f3 (double x) +{ + double x_2 = x * x; + cl++; + + return x * x_2 + 3 * x_2 + 16; +} + +double f4 (double x) +{ + double x_2 = x * x; + cl++; + + return 3 - 2 * x_2 - x_2 * x_2; +} + +double f5 (double x) +{ + cl++; + return sqrt(fabs(x) + 1) - 2; +} + +double f6 (double x) +{ + cl++; + return sqrt(sqrt(fabs(x) + 1) + 1) - 2; +} + + diff --git a/2025.05.02/06Ex/init_f.h b/2025.05.02/06Ex/init_f.h new file mode 100644 index 0000000..ee5e8e8 --- /dev/null +++ b/2025.05.02/06Ex/init_f.h @@ -0,0 +1,13 @@ +#ifndef INIT_F_H +#define INIT_F_H + +int get_call_count (void); +double f0 (double x); +double f1 (double x); +double f2 (double x); +double f3 (double x); +double f4 (double x); +double f5 (double x); +double f6 (double x); + +#endif diff --git a/2025.05.02/06Ex/main.c b/2025.05.02/06Ex/main.c new file mode 100644 index 0000000..442f122 --- /dev/null +++ b/2025.05.02/06Ex/main.c @@ -0,0 +1,49 @@ +#include +#include +#include + +#include "init_f.h" +#include "solve.h" + +/* ./a.out a b eps M k */ +int main(int argc, char *argv[]) +{ + double t, a, b, eps, x = 0; + int m, k, cl, it, task = 1; + + double (*f) (double); + double (*f_lst[]) (double) = {f0, f1, f2, f3, f4, f5, f6}; + int len_f = sizeof(f_lst) / sizeof(f_lst[0]); + + if ( + !((argc == 6) && + sscanf(argv[1], "%lf", &a) == 1 && + sscanf(argv[2], "%lf", &b) == 1 && + (a <= b) && + (sscanf(argv[3], "%lf", &eps) == 1 && (eps >= 0)) && + ((sscanf(argv[4], "%d", &m) == 1) && m > 0) && + ((sscanf(argv[5], "%d", &k) == 1) && ((0 <= k) && (k <= len_f)))) + ) { + fprintf(stderr, "Usage: %s a b eps M k\n", argv[0]); + return -1; + } + + f = f_lst[k]; + + t = clock(); + it = t1_solve(f, a, b, eps, m, &x); + t = (clock() - t) / CLOCKS_PER_SEC; + + cl = get_call_count(); + + if (it < 0) + { + fprintf(stdout, "%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], task, cl, t); + return -2; + } else + { + printf("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], task, x, f(x), it, cl, t); + return 0; + } +} + diff --git a/2025.05.02/06Ex/solve.c b/2025.05.02/06Ex/solve.c new file mode 100644 index 0000000..233ee33 --- /dev/null +++ b/2025.05.02/06Ex/solve.c @@ -0,0 +1,103 @@ +#include "solve.h" + +#include +#include +#include +#include +#include + +int t1_solve ( + double (*f) (double), + double a, double b, + double eps, int m, double *x +) { + int it = 0; + uint64_t bits; + double c = DBL_MAX, y, y_a = f(a), y_b = f(b); + bool sgn_a, sgn_b, sgn_c; + + memcpy(&bits, &y_a, sizeof(bits)); + sgn_a = (bits >> 63) & 1; + memcpy(&bits, &y_b, sizeof(bits)); + sgn_b = (bits >> 63) & 1; + + if (fabs(y_a) - eps < DBL_EPSILON) + { + *x = a; + return 1; + } if (fabs(y_b) - eps < DBL_EPSILON) + { + *x = b; + return 1; + } + + if (sgn_a == sgn_b) + { + *x = DBL_MAX; + return -1; + } + + for (it = 1; it <= m; ++it) + { + c = (a + b) * 0.5; + y = f(c); + + memcpy(&bits, &y, sizeof(bits)); + sgn_c = (bits >> 63) & 1; + + if (fabs(y) - eps < DBL_EPSILON) + break; + else if ((fabs(c - a) < DBL_EPSILON) || (fabs(c - b) < DBL_EPSILON)) + it = m+1; + else if (sgn_c == sgn_a) + { + a = c; + y_a = y; + } else if (sgn_c == sgn_b) + { + b = c; + y_b = y; + } + } + + if (it > m) + it = -1; + + *x = c; + + return it; +} + + + +int t6_solve ( + double (*f) (double), + const int m, double *d + double a, double b, + const double eps, const int M, double *x +) { + const int len = m + 1; + + double *y_lst = d; + double *x_lst = d + len; + double *t_lst = d + (len << 1); + + double last_x = a; + double last_y = f(a); + const int h = (b - a) / m; + + y_lst[0] = last_y; + x_lst[0] = last_x; + t_lst[0] = last_x; + + for (int i = 1, double t_x = a ; i < len ; i++, t_x += h) + { + double t_y = f(t_x); + + y_lst[i] = t_y; + x_lst[i] = t_x; + + + } + +} diff --git a/2025.05.02/06Ex/solve.h b/2025.05.02/06Ex/solve.h new file mode 100644 index 0000000..9b10deb --- /dev/null +++ b/2025.05.02/06Ex/solve.h @@ -0,0 +1,10 @@ +#ifndef SOLVE_H +#define SOLVE_H + +int t1_solve ( + double (*f) (double), + double a, double b, + double eps, int m, double *x + ); + +#endif diff --git a/2025.05.09/04Ex/Makefile b/2025.05.09/04Ex/Makefile new file mode 100644 index 0000000..0c97eb9 --- /dev/null +++ b/2025.05.09/04Ex/Makefile @@ -0,0 +1,42 @@ +WFLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused \ +-Wempty-body -Wlogical-op -Wold-style-declaration -Wmissing-parameter-type \ +-Wignored-qualifiers -Winit-self -Wshadow -Wtype-limits \ +-Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 \ +-Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs \ +-Wmissing-prototypes -Wmissing-declarations -Wold-style-definition \ +-Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal \ +-Wwrite-strings -Wno-long-long -std=gnu99 -Wstrict-prototypes \ +-Wmissing-field-initializers -Wpointer-sign + +LDFLAGS = -std=gnu99 -mfpmath=sse -O3 +LDLIBS = -lm + +ifeq ($(OS),Windows_NT) + EXE = exe + CLEAN = del + LDLIBS += -lssp +else + EXE = out + CLEAN = rm -f +endif + +TARGET = a04.$(EXE) +OBJ = main.o solve.o init_f.o + +%.o: %.c + gcc $(WFLAGS) $(LDFLAGS) -c $< -o $@ + +$(TARGET): $(OBJ) + gcc $^ -o $@ $(LDLIBS) + +# Отладочная сборка (gdb) +gdb: LDFLAGS = -std=gnu99 -mfpmath=sse -g -O0 +gdb: clean $(TARGET) + +# Профилировочная сборка (gprof) +prof: LDFLAGS += -pg +prof: LDLIBS += -pg +prof: clean $(TARGET) + +clean: + $(CLEAN) *.o *.$(EXE) diff --git a/2025.05.09/04Ex/init_f.c b/2025.05.09/04Ex/init_f.c new file mode 100644 index 0000000..584d534 --- /dev/null +++ b/2025.05.09/04Ex/init_f.c @@ -0,0 +1,61 @@ +#include "init_f.h" + +#include + + +static int cl = 0; + +int get_call_count (void) +{ + return cl; +} + +double f0 (double x) +{ + cl++; + (void)x; + + return 1; +} + +double f1 (double x) +{ + cl++; + return x + 1; +} + +double f2 (double x) +{ + cl++; + return x * x + x + 1; +} + +double f3 (double x) +{ + double x_2 = x * x; + cl++; + + return x * x_2 + x_2 + x + 1; +} + +double f4 (double x) +{ + double x_2 = x * x; + double x_3 = x_2 * x; + cl++; + + return x * x_3 + x_3 + x_2 + x + 1; +} + +double f5 (double x) +{ + cl++; + return exp(-x); +} + +double f6 (double x) +{ + cl++; + return 1 / (25 * x * x + 1); +} + diff --git a/2025.05.09/04Ex/init_f.h b/2025.05.09/04Ex/init_f.h new file mode 100644 index 0000000..ee5e8e8 --- /dev/null +++ b/2025.05.09/04Ex/init_f.h @@ -0,0 +1,13 @@ +#ifndef INIT_F_H +#define INIT_F_H + +int get_call_count (void); +double f0 (double x); +double f1 (double x); +double f2 (double x); +double f3 (double x); +double f4 (double x); +double f5 (double x); +double f6 (double x); + +#endif diff --git a/2025.05.09/04Ex/main.c b/2025.05.09/04Ex/main.c new file mode 100644 index 0000000..3809d11 --- /dev/null +++ b/2025.05.09/04Ex/main.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include + +#include "init_f.h" +#include "solve.h" + +/* ./a04.out a b n k */ +int main (int argc, char *argv[]) +{ + double t, x, a, b; + int k, n, cl, task = 4; + + double (*f_lst[]) (double) = {f0, f1, f2, f3, f4, f5, f6}; + int len_f = sizeof(f_lst) / sizeof(f_lst[0]); + + if ( + !((argc == 5) && + sscanf(argv[1], "%lf", &a) == 1 && + sscanf(argv[2], "%lf", &b) == 1 && + ((sscanf(argv[3], "%d", &n) == 1) && (n > 0)) && + ((sscanf(argv[4], "%d", &k) == 1) && ((0 <= k) && (k <= len_f)))) + ) { + fprintf(stderr, "Usage: %s x h k\n", argv[0]); + return -1; + } + + + t = clock(); + d = t4_solve(f_lst[k], x, h); + t = (clock() - t) / CLOCKS_PER_SEC; + + cl = get_call_count(); + + if (fabs(d - DBL_MAX) < DBL_EPSILON) + { + fprintf (stdout, "%s : Task = %d Method is not applicable Count = %d T = %.2f\n", argv[0], task, cl, t); + return -2; + } else + { + fprintf (stdout, "%s : Task = %d Res = %e Count = %d T = %.2f\n", argv[0], task, d, cl, t); + return 0; + } +} + diff --git a/2025.05.09/04Ex/solve.c b/2025.05.09/04Ex/solve.c new file mode 100644 index 0000000..5270648 --- /dev/null +++ b/2025.05.09/04Ex/solve.c @@ -0,0 +1,14 @@ +#include "solve.h" + +#include +#include + +int t3_solve ( + double (*f) (double), + double x, double h +) { + if (h < DBL_EPSILON) + return DBL_MAX; + return (f(x + h) - 2 * f(x) + f(x - h)) / (h * h); +} + diff --git a/2025.05.09/04Ex/solve.h b/2025.05.09/04Ex/solve.h new file mode 100644 index 0000000..c36855e --- /dev/null +++ b/2025.05.09/04Ex/solve.h @@ -0,0 +1,9 @@ +#ifndef SOLVE_H +#define SOLVE_H + +int t3_solve ( + double (*f) (double), + double x, double h +); + +#endif