Task 12 is done

This commit is contained in:
AZEN-SGG 2025-05-15 20:42:22 +03:00
parent e0046e37ef
commit f7e5c0b877
6 changed files with 140 additions and 13 deletions

View file

@ -10,36 +10,50 @@ int t12_solve (
double (*yt) (double),
double a, double b,
double eps, double *res
) {
) {
int it;
double xa = xt(a), ya = yt(a);
double xb = xt(b), yb = yt(b);
double xl = xa, yl = yb;
int n = 1;
int n = 2;
double h = (b - a) * 0.5;
double x = xt(b) - xt(a);
double y = yt(b) - yt(a);
double x = xb - xl;
double y = yb - yl;
double len_n = sqrt(x * x + y * y);
for (it = 1; it <= MAX_ITER; ++it)
{
double t = a;
double tn = a + h;
double len_2n = 0;
for (int i = 0; i < n; i++)
{
x = xt(tn) - xt(t);
y = yt(tn) - yt(t);
len_2n += sqrt(x * x + y * y);
t = tn;
for (int i = 1; i < n; i++)
{
double xc = xt(tn);
double yc = yt(tn);
x = xc - xl;
y = yc - yl;
len_2n += sqrt(x * x + y * y);
xl = xc;
yl = yc;
tn += h;
}
x = xb - xl;
y = yb - yl;
len_2n += sqrt(x * x + y * y);
h *= 0.5;
if (fabs(len_2n - len_n) < eps)
break;
xl = xa;
yl = ya;
len_n = len_2n;
n <<= 1;
}

Binary file not shown.

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 8 9 10 11
NUMS = 1 2 3 4 5 6 7 8 9 10 11 12
OUTS = $(foreach n,$(NUMS),$(shell printf "a%02d.out\n" "$(n)"))

45
2025.05.09/dist/Krivoruchenko_SK/a12.c vendored Normal file
View file

@ -0,0 +1,45 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "init_f.h"
#include "solve.h"
/* ./a12.out a b eps k_x k_y */
int main (int argc, char *argv[])
{
double t, integral, a, b, eps;
int x, y, n, calls, task = 12;
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 &&
((sscanf(argv[3], "%lf", &eps) == 1) && (eps > 0)) &&
((sscanf(argv[4], "%d", &x) == 1) && ((0 <= x) && (x < len_f))) &&
((sscanf(argv[5], "%d", &y) == 1) && ((0 <= y) && (y < len_f))))
) {
fprintf(stderr, "Usage: %s a b eps k_x k_y\n", argv[0]);
return -1;
}
t = clock();
n = t12_solve(f_lst[x], f_lst[y], 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;
}
}

View file

@ -315,3 +315,64 @@ double t11_solve (
}
// -------
int t12_solve (
double (*xt) (double),
double (*yt) (double),
double a, double b,
double eps, double *res
) {
int it;
double xa = xt(a), ya = yt(a);
double xb = xt(b), yb = yt(b);
double xl = xa, yl = yb;
int n = 2;
double h = (b - a) * 0.5;
double x = xb - xl;
double y = yb - yl;
double len_n = sqrt(x * x + y * y);
for (it = 1; it <= MAX_ITER; ++it)
{
double tn = a + h;
double len_2n = 0;
for (int i = 1; i < n; i++)
{
double xc = xt(tn);
double yc = yt(tn);
x = xc - xl;
y = yc - yl;
len_2n += sqrt(x * x + y * y);
xl = xc;
yl = yc;
tn += h;
}
x = xb - xl;
y = yb - yl;
len_2n += sqrt(x * x + y * y);
h *= 0.5;
if (fabs(len_2n - len_n) < eps)
break;
xl = xa;
yl = ya;
len_n = len_2n;
n <<= 1;
}
if (it > MAX_ITER)
return -1;
*res = len_n;
return n;
}

View file

@ -100,4 +100,11 @@ double t11_solve (
// -------
int t12_solve (
double (*x) (double),
double (*y) (double),
double a, double b,
double eps, double *res
);
#endif