Add 8, 9, 10 and 11 tasks to dist

This commit is contained in:
AZEN-SGG 2025-05-14 20:22:24 +03:00
parent c40059bcdc
commit ff85cc43fe
7 changed files with 375 additions and 1 deletions

View file

@ -2,7 +2,7 @@ FLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused -Wcast-align -Werror -pe
OBJ_COMMON = solve.o
NUMS = 1 2 3 4 5 6 7
NUMS = 1 2 3 4 5 6 7 8 9 10 11
OUTS = $(foreach n,$(NUMS),$(shell printf "a%02d.out\n" "$(n)"))

44
2025.05.09/dist/Krivoruchenko_SK/a08.c vendored Normal file
View file

@ -0,0 +1,44 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "init_f.h"
#include "solve.h"
/* ./a08.out a b eps k */
int main (int argc, char *argv[])
{
double t, integral, a, b, eps;
int k, n, calls, task = 8;
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], "%lf", &eps) == 1) && (eps > 0)) &&
((sscanf(argv[4], "%d", &k) == 1) && ((0 <= k) && (k < len_f))))
) {
fprintf(stderr, "Usage: %s a b eps k\n", argv[0]);
return -1;
}
t = clock();
n = t8_solve(f_lst[k], a, b, eps, &integral);
t = (clock() - t) / CLOCKS_PER_SEC;
calls = get_call_count();
if (n < 0) {
fprintf (stdout, "%s : Task = %d Method is not applicable Count = %d T = %.2f\n", argv[0], task, calls, t);
return -2;
} else {
fprintf (stdout, "%s : Task = %d Res = %e N = %d Count = %d T = %.2f\n", argv[0], task, integral, n, calls, t);
return 0;
}
}

44
2025.05.09/dist/Krivoruchenko_SK/a09.c vendored Normal file
View file

@ -0,0 +1,44 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "init_f.h"
#include "solve.h"
/* ./a09.out a b eps k */
int main (int argc, char *argv[])
{
double t, integral, a, b, eps;
int k, n, calls, task = 9;
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], "%lf", &eps) == 1) && (eps > 0)) &&
((sscanf(argv[4], "%d", &k) == 1) && ((0 <= k) && (k < len_f))))
) {
fprintf(stderr, "Usage: %s a b eps k\n", argv[0]);
return -1;
}
t = clock();
n = t9_solve(f_lst[k], a, b, eps, &integral);
t = (clock() - t) / CLOCKS_PER_SEC;
calls = get_call_count();
if (n < 0) {
fprintf (stdout, "%s : Task = %d Method is not applicable Count = %d T = %.2f\n", argv[0], task, calls, t);
return -2;
} else {
fprintf (stdout, "%s : Task = %d Res = %e N = %d Count = %d T = %.2f\n", argv[0], task, integral, n, calls, t);
return 0;
}
}

42
2025.05.09/dist/Krivoruchenko_SK/a10.c vendored Normal file
View file

@ -0,0 +1,42 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "init_f.h"
#include "solve.h"
/* ./a10.out a eps k */
int main (int argc, char *argv[])
{
double t, integral, a, b, eps;
int k, calls, task = 10;
double (*f_lst[]) (double) = {f0, f1, f2, f3, f4, f5, f6};
int len_f = sizeof(f_lst) / sizeof(f_lst[0]);
if (
!((argc == 4) &&
sscanf(argv[1], "%lf", &a) == 1 &&
((sscanf(argv[2], "%lf", &eps) == 1) && (eps > 0)) &&
((sscanf(argv[3], "%d", &k) == 1) && ((0 <= k) && (k < len_f))))
) {
fprintf(stderr, "Usage: %s a eps k\n", argv[0]);
return -1;
}
t = clock();
b = t10_solve(f_lst[k], a, eps, &integral);
t = (clock() - t) / CLOCKS_PER_SEC;
calls = get_call_count();
if (b < 0) {
fprintf (stdout, "%s : Task = %d Method is not applicable Count = %d T = %.2f\n", argv[0], task, calls, t);
return -2;
} else {
fprintf (stdout, "%s : Task = %d Res = %e B = %e Count = %d T = %.2f\n", argv[0], task, integral, b, calls, t);
return 0;
}
}

42
2025.05.09/dist/Krivoruchenko_SK/a11.c vendored Normal file
View file

@ -0,0 +1,42 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "init_f.h"
#include "solve.h"
/* ./a11.out a eps k */
int main (int argc, char *argv[])
{
double t, integral, a, b, eps;
int k, calls, task = 11;
double (*f_lst[]) (double) = {f0, f1, f2, f3, f4, f5, f6};
int len_f = sizeof(f_lst) / sizeof(f_lst[0]);
if (
!((argc == 4) &&
sscanf(argv[1], "%lf", &a) == 1 &&
((sscanf(argv[2], "%lf", &eps) == 1) && (eps > 0)) &&
((sscanf(argv[3], "%d", &k) == 1) && ((0 <= k) && (k < len_f))))
) {
fprintf(stderr, "Usage: %s a eps k\n", argv[0]);
return -1;
}
t = clock();
b = t11_solve(f_lst[k], a, eps, &integral);
t = (clock() - t) / CLOCKS_PER_SEC;
calls = get_call_count();
if (b < 0) {
fprintf (stdout, "%s : Task = %d Method is not applicable Count = %d T = %.2f\n", argv[0], task, calls, t);
return -2;
} else {
fprintf (stdout, "%s : Task = %d Res = %e B = %e Count = %d T = %.2f\n", argv[0], task, integral, b, calls, t);
return 0;
}
}

View file

@ -146,3 +146,172 @@ double t7_solve (
// -------
int t8_solve (
double (*f) (double),
double a, double b,
double eps, double *res
) {
int it;
double n = 1;
double h = (b - a);
double integ_n = (f(a) + f(b)) * h*0.5;
for (it = 1; it <= MAX_ITER; ++it)
{
double x = a + h*0.5;
double integ_2n = 0;
for (int i = 0; i < n; i++)
{
integ_2n += f(x);
x += h;
}
h *= 0.5;
integ_2n = integ_2n * h + integ_n * 0.5;
if (fabs(integ_2n - integ_n) < eps)
break;
integ_n = integ_2n;
n *= 2;
}
if (it > MAX_ITER)
return -1;
*res = integ_n;
return n;
}
// -------
int t9_solve (
double (*f) (double),
double a, double b,
double eps, double *res
) {
int it;
double integ_n;
int n = 2;
double h = (b - a) * 0.5;
double s1 = (f(a) + f(b)) * h/3;
double s2 = f(a + h) * h*4/3;
for (it = 1; it <= MAX_ITER; ++it)
{
double x = a + h*0.5;
double s2_2n = 0;
for (int i = 0; i < n; i++)
{
s2_2n += f(x);
x += h;
}
s2_2n *= h*2/3;
if (fabs((s2_2n - s1 * 0.5) - s2 * 0.75) < eps) {
integ_n = s1 + s2;
break;
}
s1 = s1 * 0.5 + s2 * 0.25;
s2 = s2_2n;
h *= 0.5;
n <<= 1;
}
if (it > MAX_ITER)
return -1;
*res = integ_n;
return n;
}
// -------
double t10_solve (
double (*f) (double),
double a, double eps,
double *res
) {
int it;
int h = 1;
double b = a;
double integ = 0;
for (it = 1; it <= MAX_ITER; ++it)
{
int n;
double ipart = 0;
b += h;
n = t8_solve(f, a, b, eps, &ipart);
if (n < 0)
return -2;
integ += ipart;
if (fabs(ipart) < eps)
break;
a = b;
h <<= 1;
}
if (it > MAX_ITER)
return -1;
*res = integ;
return b;
}
// -------
double t11_solve (
double (*f) (double),
double a, double eps,
double *res
) {
int it;
int h = 1;
double b = a;
double integ = 0;
for (it = 1; it <= MAX_ITER; ++it)
{
int n;
double ipart = 0;
b += h;
n = t9_solve(f, a, b, eps, &ipart);
if (n < 0)
return -2;
integ += ipart;
if (fabs(ipart) < eps)
break;
a = b;
h <<= 1;
}
if (it > MAX_ITER)
return -1;
*res = integ;
return b;
}
// -------

View file

@ -2,6 +2,7 @@
#define SOLVE_H
#define NUM_FPE 1e-300
#define MAX_ITER 30
#include "init_f.h"
@ -67,4 +68,36 @@ double t7_solve (
// -------
int t8_solve (
double (*f) (double),
double a, double b,
double eps, double *res
);
// -------
int t9_solve (
double (*f) (double),
double a, double b,
double eps, double *res
);
// -------
double t10_solve (
double (*f) (double),
double a, double eps,
double *res
);
// -------
double t11_solve (
double (*f) (double),
double a, double eps,
double *res
);
// -------
#endif