Task 12 is done
This commit is contained in:
parent
e0046e37ef
commit
f7e5c0b877
6 changed files with 140 additions and 13 deletions
|
@ -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;
|
||||
}
|
||||
|
|
BIN
2025.05.09/dist/Krivoruchenko_SK/.nfs000000000e4a0ec40000000a
vendored
Normal file
BIN
2025.05.09/dist/Krivoruchenko_SK/.nfs000000000e4a0ec40000000a
vendored
Normal file
Binary file not shown.
2
2025.05.09/dist/Krivoruchenko_SK/Makefile
vendored
2
2025.05.09/dist/Krivoruchenko_SK/Makefile
vendored
|
@ -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
45
2025.05.09/dist/Krivoruchenko_SK/a12.c
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
|
61
2025.05.09/dist/Krivoruchenko_SK/solve.c
vendored
61
2025.05.09/dist/Krivoruchenko_SK/solve.c
vendored
|
@ -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;
|
||||
}
|
||||
|
|
7
2025.05.09/dist/Krivoruchenko_SK/solve.h
vendored
7
2025.05.09/dist/Krivoruchenko_SK/solve.h
vendored
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue