diff --git a/2025.04.04/Krivoruchenko_SK.zip b/2025.04.04/Krivoruchenko_SK.zip index 387948d..ea0d997 100644 Binary files a/2025.04.04/Krivoruchenko_SK.zip and b/2025.04.04/Krivoruchenko_SK.zip differ diff --git a/2025.04.04/dist/Krivoruchenko_SK/profile.txt b/2025.04.04/dist/Krivoruchenko_SK/profile.txt deleted file mode 100644 index 87e6946..0000000 --- a/2025.04.04/dist/Krivoruchenko_SK/profile.txt +++ /dev/null @@ -1,187 +0,0 @@ -Flat profile: - -Each sample counts as 0.01 seconds. - % cumulative self self total - time seconds seconds calls s/call s/call name - 57.69 143.36 143.36 1 143.36 248.19 t14_solve - 42.17 248.15 104.79 6000 0.02 0.02 gauss_inverse - 0.08 248.35 0.20 2 0.10 0.15 read_or_init_matrix - 0.04 248.45 0.10 72000000 0.00 0.00 f2 - 0.02 248.49 0.04 1 0.04 0.04 get_matrix_norm - 0.00 248.49 0.00 2 0.00 0.00 print_matrix - 0.00 248.49 0.00 1 0.00 0.00 get_r1 - 0.00 248.49 0.00 1 0.00 0.00 get_r2 - 0.00 248.49 0.00 1 0.00 0.00 init_identity_matrix - - % the percentage of the total running time of the -time program used by this function. - -cumulative a running sum of the number of seconds accounted - seconds for by this function and those listed above it. - - self the number of seconds accounted for by this -seconds function alone. This is the major sort for this - listing. - -calls the number of times this function was invoked, if - this function is profiled, else blank. - - self the average number of milliseconds spent in this -ms/call function per call, if this function is profiled, - else blank. - - total the average number of milliseconds spent in this -ms/call function and its descendents per call, if this - function is profiled, else blank. - -name the name of the function. This is the minor sort - for this listing. The index shows the location of - the function in the gprof listing. If the index is - in parenthesis it shows where it would appear in - the gprof listing if it were to be printed. - -Copyright (C) 2012-2022 Free Software Foundation, Inc. - -Copying and distribution of this file, with or without modification, -are permitted in any medium without royalty provided the copyright -notice and this notice are preserved. - - Call graph (explanation follows) - - -granularity: each sample hit covers 4 byte(s) for 0.00% of 248.49 seconds - -index % time self children called name - -[1] 100.0 0.00 248.49 main [1] - 143.36 104.83 1/1 t14_solve [2] - 0.20 0.10 2/2 read_or_init_matrix [4] - 0.00 0.00 2/2 print_matrix [7] - 0.00 0.00 1/1 init_identity_matrix [10] - 0.00 0.00 1/1 get_r1 [8] - 0.00 0.00 1/1 get_r2 [9] ------------------------------------------------ - 143.36 104.83 1/1 main [1] -[2] 99.9 143.36 104.83 1 t14_solve [2] - 104.79 0.00 6000/6000 gauss_inverse [3] - 0.04 0.00 1/1 get_matrix_norm [6] ------------------------------------------------ - 104.79 0.00 6000/6000 t14_solve [2] -[3] 42.2 104.79 0.00 6000 gauss_inverse [3] ------------------------------------------------ - 0.20 0.10 2/2 main [1] -[4] 0.1 0.20 0.10 2 read_or_init_matrix [4] - 0.10 0.00 72000000/72000000 f2 [5] ------------------------------------------------ - 0.10 0.00 72000000/72000000 read_or_init_matrix [4] -[5] 0.0 0.10 0.00 72000000 f2 [5] ------------------------------------------------ - 0.04 0.00 1/1 t14_solve [2] -[6] 0.0 0.04 0.00 1 get_matrix_norm [6] ------------------------------------------------ - 0.00 0.00 2/2 main [1] -[7] 0.0 0.00 0.00 2 print_matrix [7] ------------------------------------------------ - 0.00 0.00 1/1 main [1] -[8] 0.0 0.00 0.00 1 get_r1 [8] ------------------------------------------------ - 0.00 0.00 1/1 main [1] -[9] 0.0 0.00 0.00 1 get_r2 [9] ------------------------------------------------ - 0.00 0.00 1/1 main [1] -[10] 0.0 0.00 0.00 1 init_identity_matrix [10] ------------------------------------------------ - - This table describes the call tree of the program, and was sorted by - the total amount of time spent in each function and its children. - - Each entry in this table consists of several lines. The line with the - index number at the left hand margin lists the current function. - The lines above it list the functions that called this function, - and the lines below it list the functions this one called. - This line lists: - index A unique number given to each element of the table. - Index numbers are sorted numerically. - The index number is printed next to every function name so - it is easier to look up where the function is in the table. - - % time This is the percentage of the `total' time that was spent - in this function and its children. Note that due to - different viewpoints, functions excluded by options, etc, - these numbers will NOT add up to 100%. - - self This is the total amount of time spent in this function. - - children This is the total amount of time propagated into this - function by its children. - - called This is the number of times the function was called. - If the function called itself recursively, the number - only includes non-recursive calls, and is followed by - a `+' and the number of recursive calls. - - name The name of the current function. The index number is - printed after it. If the function is a member of a - cycle, the cycle number is printed between the - function's name and the index number. - - - For the function's parents, the fields have the following meanings: - - self This is the amount of time that was propagated directly - from the function into this parent. - - children This is the amount of time that was propagated from - the function's children into this parent. - - called This is the number of times this parent called the - function `/' the total number of times the function - was called. Recursive calls to the function are not - included in the number after the `/'. - - name This is the name of the parent. The parent's index - number is printed after it. If the parent is a - member of a cycle, the cycle number is printed between - the name and the index number. - - If the parents of the function cannot be determined, the word - `' is printed in the `name' field, and all the other - fields are blank. - - For the function's children, the fields have the following meanings: - - self This is the amount of time that was propagated directly - from the child into the function. - - children This is the amount of time that was propagated from the - child's children to the function. - - called This is the number of times the function called - this child `/' the total number of times the child - was called. Recursive calls by the child are not - listed in the number after the `/'. - - name This is the name of the child. The child's index - number is printed after it. If the child is a - member of a cycle, the cycle number is printed - between the name and the index number. - - If there are any cycles (circles) in the call graph, there is an - entry for the cycle-as-a-whole. This entry shows who called the - cycle (as parents) and the members of the cycle (as children.) - The `+' recursive calls entry shows the number of function calls that - were internal to the cycle, and the calls entry for each member shows, - for that member, how many times it was called from other members of - the cycle. - -Copyright (C) 2012-2022 Free Software Foundation, Inc. - -Copying and distribution of this file, with or without modification, -are permitted in any medium without royalty provided the copyright -notice and this notice are preserved. - -Index by function name - - [5] f2 [8] get_r1 [7] print_matrix - [3] gauss_inverse [9] get_r2 [4] read_or_init_matrix - [6] get_matrix_norm [10] init_identity_matrix [2] t14_solve diff --git a/2025.04.18/08Ex/solve.c b/2025.04.18/08Ex/solve.c index 4c24573..b5e9f0f 100644 --- a/2025.04.18/08Ex/solve.c +++ b/2025.04.18/08Ex/solve.c @@ -2,7 +2,6 @@ #include "contin_func.h" #include -#include #include #include diff --git a/2025.04.18/Krivoruchenko_SK.zip b/2025.04.18/Krivoruchenko_SK.zip new file mode 100644 index 0000000..bdcbbfe Binary files /dev/null and b/2025.04.18/Krivoruchenko_SK.zip differ diff --git a/2025.04.18/dist/Krivoruchenko_SK/Makefile b/2025.04.18/dist/Krivoruchenko_SK/Makefile index cbfc3d3..b371b8d 100644 --- a/2025.04.18/dist/Krivoruchenko_SK/Makefile +++ b/2025.04.18/dist/Krivoruchenko_SK/Makefile @@ -5,7 +5,7 @@ FLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused -Wcast-align -Werror -pe %.o: %.c gcc -c $(FLAGS) $< -all: a01.out a02.out a03.out a04.out a05.out +all: a01.out a02.out a03.out a04.out a05.out a06.out a07.out a08.out solve.o: solve.c solve.h array_io.o: array_io.c array_io.h diff --git a/2025.04.18/dist/Krivoruchenko_SK/a06.c b/2025.04.18/dist/Krivoruchenko_SK/a06.c new file mode 100644 index 0000000..bf43037 --- /dev/null +++ b/2025.04.18/dist/Krivoruchenko_SK/a06.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +#include "io_status.h" +#include "solve.h" + +/* ./a.out x eps */ +int main(int argc, char *argv[]) +{ + double x, eps, t, r1 = 0, r2 = 0; + int task = 6; + + if ( + !((argc == 3) && + sscanf(argv[1], "%le", &x) == 1 && + ((sscanf(argv[2], "%le", &eps) == 1) && eps > 0)) + ) { + fprintf(stderr, "Usage: %s x eps\n", argv[0]); + return 1; + } + + t = clock(); + r1 = fcos(x, eps); + t = (clock() - t) / CLOCKS_PER_SEC; + + r2 = fabs(r1 - cos(x)); + + printf("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], task, r1, r2, t); + + return 0; +} + diff --git a/2025.04.18/dist/Krivoruchenko_SK/a07.c b/2025.04.18/dist/Krivoruchenko_SK/a07.c new file mode 100644 index 0000000..040df9e --- /dev/null +++ b/2025.04.18/dist/Krivoruchenko_SK/a07.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +#include "io_status.h" +#include "solve.h" + +/* ./a.out x eps */ +int main(int argc, char *argv[]) +{ + double x, eps, t, r1 = 0, r2 = 0; + int task = 7; + + if ( + !((argc == 3) && + sscanf(argv[1], "%le", &x) == 1 && + ((sscanf(argv[2], "%le", &eps) == 1) && eps > 0)) + ) { + fprintf(stderr, "Usage: %s x eps\n", argv[0]); + return 1; + } + + t = clock(); + r1 = fexp(x, eps); + t = (clock() - t) / CLOCKS_PER_SEC; + + r2 = fabs(r1 - exp(x)); + + printf("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], task, r1, r2, t); + + return 0; +} + diff --git a/2025.04.18/dist/Krivoruchenko_SK/a08.c b/2025.04.18/dist/Krivoruchenko_SK/a08.c new file mode 100644 index 0000000..f7519c6 --- /dev/null +++ b/2025.04.18/dist/Krivoruchenko_SK/a08.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +#include "io_status.h" +#include "solve.h" + +/* ./a.out x eps */ +int main(int argc, char *argv[]) +{ + double x, eps, t, r1 = 0, r2 = 0; + int task = 8; + + if ( + !((argc == 3) && + ((sscanf(argv[1], "%le", &x) == 1) && x > 0) && + ((sscanf(argv[2], "%le", &eps) == 1) && eps > 0)) + ) { + fprintf(stderr, "Usage: %s x eps\n", argv[0]); + return 1; + } + + t = clock(); + r1 = dln(x, eps); + t = (clock() - t) / CLOCKS_PER_SEC; + + r2 = fabs(r1 - log(x)); + + printf("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], task, r1, r2, t); + + return 0; +} + diff --git a/2025.04.18/dist/Krivoruchenko_SK/contin_func.c b/2025.04.18/dist/Krivoruchenko_SK/contin_func.c index 4267921..c97e35d 100644 --- a/2025.04.18/dist/Krivoruchenko_SK/contin_func.c +++ b/2025.04.18/dist/Krivoruchenko_SK/contin_func.c @@ -36,3 +36,39 @@ double scos (const double x, const double eps) return value; } + +double sexp (const double x, const double eps) +{ + double value = 1; + double monom = x; + int i = 1; + + while (monom - eps >= DBL_EPSILON) + { + value += monom; + + i++; + monom *= x/i; + } + + return value; +} + +double fln (const double x, const double eps) +{ + const double z = (x - 1) / (x + 1); + double value = 0; + double monom = z, el = z; + int i = 1; + + while (el - eps > DBL_EPSILON) + { + value += el; + + i+=2; + monom *= z*z; + el = monom / i; + } + + return 2 * value; +} \ No newline at end of file diff --git a/2025.04.18/dist/Krivoruchenko_SK/contin_func.h b/2025.04.18/dist/Krivoruchenko_SK/contin_func.h index 404674a..d7d2055 100644 --- a/2025.04.18/dist/Krivoruchenko_SK/contin_func.h +++ b/2025.04.18/dist/Krivoruchenko_SK/contin_func.h @@ -3,5 +3,7 @@ double ssin (const double x, const double eps); double scos (const double x, const double eps); +double sexp (const double x, const double eps); +double fln (const double x, const double eps); #endif diff --git a/2025.04.18/dist/Krivoruchenko_SK/solve.c b/2025.04.18/dist/Krivoruchenko_SK/solve.c index dc0422a..7bf86ce 100644 --- a/2025.04.18/dist/Krivoruchenko_SK/solve.c +++ b/2025.04.18/dist/Krivoruchenko_SK/solve.c @@ -2,6 +2,7 @@ #include "contin_func.h" #include +#include #include #include @@ -222,3 +223,81 @@ double fsin (double x, const double eps) return answer; } + +double fcos (double x, const double eps) +{ + double answer; + short flag = 1; + + if (x - M_PI*2 >= DBL_EPSILON) + x = fmod(x, M_PI*2); + + if (x - M_PI >= DBL_EPSILON) + { + x -= M_PI; + flag *= -1; + } + + if (x - 1 >= DBL_EPSILON) + { + x -= M_PI_2; + flag *= -2; + } + + if (abs(flag) == 2) + { + x /= 2; + + answer = ((flag > 0) - (flag < 0)) * (2 * ssin(x, eps) * scos(x, eps)); + } else + answer = flag * scos(x, eps); + + return answer; +} + +double fexp (double x, const double eps) +{ + double integral, fractal, answer = 1; + bool is_negative = false; + + if (x < DBL_EPSILON) + { + is_negative = true; + x = -x; + } + + integral = floor(x); + fractal = x - integral; + + for (double i = 0; (integral - i) > DBL_EPSILON; ++i) + answer *= M_E; + + answer *= sexp(fractal, eps); + if (is_negative) + answer = 1. / answer; + + return answer; +} + +double dln (double x, const double eps) +{ + double value = 0; + int b = 0; + + while (x - 2 > DBL_EPSILON) + { + x *= 0.5; + b++; + } + + while (x - 1 <= DBL_EPSILON) + { + x *= 2; + b--; + } + + value = fln(x, eps); + + value += b * M_LN2; + return value; +} diff --git a/2025.04.18/dist/Krivoruchenko_SK/solve.h b/2025.04.18/dist/Krivoruchenko_SK/solve.h index f81212d..d9a44eb 100644 --- a/2025.04.18/dist/Krivoruchenko_SK/solve.h +++ b/2025.04.18/dist/Krivoruchenko_SK/solve.h @@ -11,5 +11,8 @@ double t4_solve ( double * restrict D ); double fsin (double x, const double eps); +double fcos (double x, const double eps); +double fexp (double x, const double eps); +double dln (double x, const double eps); #endif