From f5e0076a8455eec5b4a515b39202217f8a8b9e71 Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Sun, 13 Oct 2024 19:28:57 +0300 Subject: Initial commit --- 5_2.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 5_2.c (limited to '5_2.c') diff --git a/5_2.c b/5_2.c new file mode 100644 index 0000000..00152e6 --- /dev/null +++ b/5_2.c @@ -0,0 +1,44 @@ +#include +#include +#include "matrix.h" + +#define MRX_SZ 6 +#define add_func(name, func) \ + double name (double x){ \ + return func; \ + } + +add_func(x2, x*x) +add_func(x2_sinx, x2(sin(x))) +add_func(sqrtx_x2, sqrt(x) * x2(x)) +add_func(sqrt_sin_x2, sqrt(sin(x2(x)))) + +const func_t funcs[MRX_SZ] = { + x2, sin, sqrt, x2_sinx, sqrtx_x2, sqrt_sin_x2 +}; + +int main(void) { + srand(time(NULL)); + // выбираем интервал для генерации случайных чисел +interval_selection: + printf("Input the borders of the interval for generated values, separated by a whitespace:\n"); + double a, b; + if (scanf("%lf %lf", &a, &b) != 2) { + SKIP_INPUT; + goto interval_selection; + } + // создаём матрицы + struct matrix m = matrix_new(1, MRX_SZ); + matrix_fill(&m, a, b); + struct matrix f_mem = matrix_new(1, MRX_SZ); + struct fmatrix f = *(struct fmatrix*)&f_mem; + for (usz i = 0; i < f.columns; ++i) f.funcs[0][i] = funcs[i]; + // делаем грязную работу + puts("A = "); matrix_print(&m); + matrix_apply(&m, &f); + puts("f(A) = "); matrix_print(&m); + // очищаем память + matrix_free(m); + matrix_free(f_mem); + return 0; +} -- cgit v1.2.3-70-g09d2