Add Kochubei's solve
This commit is contained in:
parent
1053f8e3c2
commit
23bf5e0903
28 changed files with 1827 additions and 0 deletions
42
2025.05.02/05Ex/Makefile
Normal file
42
2025.05.02/05Ex/Makefile
Normal file
|
@ -0,0 +1,42 @@
|
|||
WFLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused \
|
||||
-Wempty-body -Wlogical-op -Wold-style-declaration -Wmissing-parameter-type \
|
||||
-Wignored-qualifiers -Winit-self -Wshadow -Wtype-limits \
|
||||
-Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 \
|
||||
-Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs \
|
||||
-Wmissing-prototypes -Wmissing-declarations -Wold-style-definition \
|
||||
-Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal \
|
||||
-Wwrite-strings -Wno-long-long -std=gnu99 -Wstrict-prototypes \
|
||||
-Wmissing-field-initializers -Wpointer-sign
|
||||
|
||||
LDFLAGS = -std=gnu99 -mfpmath=sse -O3
|
||||
LDLIBS = -lm
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
EXE = exe
|
||||
CLEAN = del
|
||||
LDLIBS += -lssp
|
||||
else
|
||||
EXE = out
|
||||
CLEAN = rm -f
|
||||
endif
|
||||
|
||||
TARGET = a015.$(EXE)
|
||||
OBJ = main.o solve.o init_f.o
|
||||
|
||||
%.o: %.c
|
||||
gcc $(WFLAGS) $(LDFLAGS) -c $< -o $@
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
gcc $^ -o $@ $(LDLIBS)
|
||||
|
||||
# Отладочная сборка (gdb)
|
||||
gdb: LDFLAGS = -std=gnu99 -mfpmath=sse -g -O0
|
||||
gdb: clean $(TARGET)
|
||||
|
||||
# Профилировочная сборка (gprof)
|
||||
prof: LDFLAGS += -pg
|
||||
prof: LDLIBS += -pg
|
||||
prof: clean $(TARGET)
|
||||
|
||||
clean:
|
||||
$(CLEAN) *.o *$(EXE)
|
61
2025.05.02/05Ex/init_f.c
Normal file
61
2025.05.02/05Ex/init_f.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include "init_f.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
static int cl = 0;
|
||||
|
||||
int get_call_count (void)
|
||||
{
|
||||
return cl;
|
||||
}
|
||||
|
||||
double f0 (double x)
|
||||
{
|
||||
cl++;
|
||||
(void)x;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
double f1 (double x)
|
||||
{
|
||||
cl++;
|
||||
return (x * 1e-100) - 1.0;
|
||||
}
|
||||
|
||||
double f2 (double x)
|
||||
{
|
||||
cl++;
|
||||
return 4 - x * x;
|
||||
}
|
||||
|
||||
double f3 (double x)
|
||||
{
|
||||
double x_2 = x * x;
|
||||
cl++;
|
||||
|
||||
return x * x_2 + 3 * x_2 + 16;
|
||||
}
|
||||
|
||||
double f4 (double x)
|
||||
{
|
||||
double x_2 = x * x;
|
||||
cl++;
|
||||
|
||||
return 3 - 2 * x_2 - x_2 * x_2;
|
||||
}
|
||||
|
||||
double f5 (double x)
|
||||
{
|
||||
cl++;
|
||||
return sqrt(fabs(x) + 1) - 2;
|
||||
}
|
||||
|
||||
double f6 (double x)
|
||||
{
|
||||
cl++;
|
||||
return sqrt(sqrt(fabs(x) + 1) + 1) - 2;
|
||||
}
|
||||
|
||||
|
13
2025.05.02/05Ex/init_f.h
Normal file
13
2025.05.02/05Ex/init_f.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef INIT_F_H
|
||||
#define INIT_F_H
|
||||
|
||||
int get_call_count (void);
|
||||
double f0 (double x);
|
||||
double f1 (double x);
|
||||
double f2 (double x);
|
||||
double f3 (double x);
|
||||
double f4 (double x);
|
||||
double f5 (double x);
|
||||
double f6 (double x);
|
||||
|
||||
#endif
|
49
2025.05.02/05Ex/main.c
Normal file
49
2025.05.02/05Ex/main.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "init_f.h"
|
||||
#include "solve.h"
|
||||
|
||||
/* ./a.out a b eps M k */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
double t, a, b, eps, x = 0;
|
||||
int m, k, cl, it, task = 1;
|
||||
|
||||
double (*f) (double);
|
||||
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 &&
|
||||
(a <= b) &&
|
||||
(sscanf(argv[3], "%lf", &eps) == 1 && (eps >= 0)) &&
|
||||
((sscanf(argv[4], "%d", &m) == 1) && m > 0) &&
|
||||
((sscanf(argv[5], "%d", &k) == 1) && ((0 <= k) && (k <= len_f))))
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s a b eps M k\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
f = f_lst[k];
|
||||
|
||||
t = clock();
|
||||
it = t1_solve(f, a, b, eps, m, &x);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
cl = get_call_count();
|
||||
|
||||
if (it < 0)
|
||||
{
|
||||
fprintf(stdout, "%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], task, cl, t);
|
||||
return -2;
|
||||
} else
|
||||
{
|
||||
printf("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], task, x, f(x), it, cl, t);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
70
2025.05.02/05Ex/solve.c
Normal file
70
2025.05.02/05Ex/solve.c
Normal file
|
@ -0,0 +1,70 @@
|
|||
#include "solve.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
int t1_solve (
|
||||
double (*f) (double),
|
||||
double a, double b,
|
||||
double eps, int m, double *x
|
||||
) {
|
||||
int it = 0;
|
||||
uint64_t bits;
|
||||
double c = DBL_MAX, y, y_a = f(a), y_b = f(b);
|
||||
bool sgn_a, sgn_b, sgn_c;
|
||||
|
||||
memcpy(&bits, &y_a, sizeof(bits));
|
||||
sgn_a = (bits >> 63) & 1;
|
||||
memcpy(&bits, &y_b, sizeof(bits));
|
||||
sgn_b = (bits >> 63) & 1;
|
||||
|
||||
if (fabs(y_a) - eps < DBL_EPSILON)
|
||||
{
|
||||
*x = a;
|
||||
return 1;
|
||||
} if (fabs(y_b) - eps < DBL_EPSILON)
|
||||
{
|
||||
*x = b;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sgn_a == sgn_b)
|
||||
{
|
||||
*x = DBL_MAX;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (it = 1; it <= m; ++it)
|
||||
{
|
||||
c = (a + b) * 0.5;
|
||||
y = f(c);
|
||||
|
||||
memcpy(&bits, &y, sizeof(bits));
|
||||
sgn_c = (bits >> 63) & 1;
|
||||
|
||||
if (fabs(y) - eps < DBL_EPSILON)
|
||||
break;
|
||||
else if ((fabs(c - a) < DBL_EPSILON) || (fabs(c - b) < DBL_EPSILON))
|
||||
it = m+1;
|
||||
else if (sgn_c == sgn_a)
|
||||
{
|
||||
a = c;
|
||||
y_a = y;
|
||||
} else if (sgn_c == sgn_b)
|
||||
{
|
||||
b = c;
|
||||
y_b = y;
|
||||
}
|
||||
}
|
||||
|
||||
if (it > m)
|
||||
it = -1;
|
||||
|
||||
*x = c;
|
||||
|
||||
return it;
|
||||
}
|
||||
|
10
2025.05.02/05Ex/solve.h
Normal file
10
2025.05.02/05Ex/solve.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
int t1_solve (
|
||||
double (*f) (double),
|
||||
double a, double b,
|
||||
double eps, int m, double *x
|
||||
);
|
||||
|
||||
#endif
|
42
2025.05.02/09Ex/Makefile
Normal file
42
2025.05.02/09Ex/Makefile
Normal file
|
@ -0,0 +1,42 @@
|
|||
WFLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused \
|
||||
-Wempty-body -Wlogical-op -Wold-style-declaration -Wmissing-parameter-type \
|
||||
-Wignored-qualifiers -Winit-self -Wshadow -Wtype-limits \
|
||||
-Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 \
|
||||
-Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs \
|
||||
-Wmissing-prototypes -Wmissing-declarations -Wold-style-definition \
|
||||
-Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal \
|
||||
-Wwrite-strings -Wno-long-long -std=gnu99 -Wstrict-prototypes \
|
||||
-Wmissing-field-initializers -Wpointer-sign
|
||||
|
||||
LDFLAGS = -std=gnu99 -mfpmath=sse -O3
|
||||
LDLIBS = -lm
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
EXE = exe
|
||||
CLEAN = del
|
||||
LDLIBS += -lssp
|
||||
else
|
||||
EXE = out
|
||||
CLEAN = rm -f
|
||||
endif
|
||||
|
||||
TARGET = a09.$(EXE)
|
||||
OBJ = main.o solve.o init_f.o
|
||||
|
||||
%.o: %.c
|
||||
gcc $(WFLAGS) $(LDFLAGS) -c $< -o $@
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
gcc $^ -o $@ $(LDLIBS)
|
||||
|
||||
# Отладочная сборка (gdb)
|
||||
gdb: LDFLAGS = -std=gnu99 -mfpmath=sse -g -O0
|
||||
gdb: clean $(TARGET)
|
||||
|
||||
# Профилировочная сборка (gprof)
|
||||
prof: LDFLAGS += -pg
|
||||
prof: LDLIBS += -pg
|
||||
prof: clean $(TARGET)
|
||||
|
||||
clean:
|
||||
$(CLEAN) *.o *$(EXE)
|
61
2025.05.02/09Ex/init_f.c
Normal file
61
2025.05.02/09Ex/init_f.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include "init_f.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
static int cl = 0;
|
||||
|
||||
int get_call_count (void)
|
||||
{
|
||||
return cl;
|
||||
}
|
||||
|
||||
double f0 (double x)
|
||||
{
|
||||
cl++;
|
||||
(void)x;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
double f1 (double x)
|
||||
{
|
||||
cl++;
|
||||
return (x * 1e-100) - 1.0;
|
||||
}
|
||||
|
||||
double f2 (double x)
|
||||
{
|
||||
cl++;
|
||||
return 4 - x * x;
|
||||
}
|
||||
|
||||
double f3 (double x)
|
||||
{
|
||||
double x_2 = x * x;
|
||||
cl++;
|
||||
|
||||
return x * x_2 + 3 * x_2 + 16;
|
||||
}
|
||||
|
||||
double f4 (double x)
|
||||
{
|
||||
double x_2 = x * x;
|
||||
cl++;
|
||||
|
||||
return 3 - 2 * x_2 - x_2 * x_2;
|
||||
}
|
||||
|
||||
double f5 (double x)
|
||||
{
|
||||
cl++;
|
||||
return sqrt(fabs(x) + 1) - 2;
|
||||
}
|
||||
|
||||
double f6 (double x)
|
||||
{
|
||||
cl++;
|
||||
return sqrt(sqrt(fabs(x) + 1) + 1) - 2;
|
||||
}
|
||||
|
||||
|
13
2025.05.02/09Ex/init_f.h
Normal file
13
2025.05.02/09Ex/init_f.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef INIT_F_H
|
||||
#define INIT_F_H
|
||||
|
||||
int get_call_count (void);
|
||||
double f0 (double x);
|
||||
double f1 (double x);
|
||||
double f2 (double x);
|
||||
double f3 (double x);
|
||||
double f4 (double x);
|
||||
double f5 (double x);
|
||||
double f6 (double x);
|
||||
|
||||
#endif
|
66
2025.05.02/09Ex/main.c
Normal file
66
2025.05.02/09Ex/main.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "init_f.h"
|
||||
#include "status.h"
|
||||
#include "solve.h"
|
||||
|
||||
/* ./a.out a b eps M k */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
double t, a, b, eps, x = 0;
|
||||
int m, k, cl, it = 0, task = 1;
|
||||
status ret;
|
||||
|
||||
double (*f) (double);
|
||||
double (*f_lst[]) (double) = {f0, f1, f2, f3, f4, f5, f6, sin}; // TODO: Remove sin
|
||||
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 &&
|
||||
(a <= b) &&
|
||||
sscanf(argv[3], "%lf", &eps) == 1 &&
|
||||
((sscanf(argv[4], "%d", &m) == 1) && m > 0) &&
|
||||
((sscanf(argv[5], "%d", &k) == 1) && ((0 <= k) && (k <= len_f))))
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s a b eps M k\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
f = f_lst[k];
|
||||
|
||||
t = clock();
|
||||
ret = t1_solve(f, a, b, eps, m, &x, &it);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
cl = get_call_count();
|
||||
|
||||
|
||||
do {
|
||||
switch (ret)
|
||||
{
|
||||
case SUCCESS:
|
||||
continue;
|
||||
case RUN_TIME:
|
||||
fprintf(stderr, "Error: with code %d - Not enough iterations!\n", ret);
|
||||
break;
|
||||
case MORE_ONE_ROOT:
|
||||
fprintf(stderr, "Error: with code %d - The same signs on the boundaries of the segment!\n", ret);
|
||||
break;
|
||||
case HIGH_ERROR:
|
||||
fprintf(stderr, "Error: with code %d - The solution was found with a high error rate!\n", ret);
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stdout, "%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], task, cl, t);
|
||||
return ret;
|
||||
} while (0);
|
||||
|
||||
printf("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], task, x, f(x), it, cl, t);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
68
2025.05.02/09Ex/solve.c
Normal file
68
2025.05.02/09Ex/solve.c
Normal file
|
@ -0,0 +1,68 @@
|
|||
#include "solve.h"
|
||||
#include "status.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
int t9_solve (
|
||||
double (*f) (double),
|
||||
double a, double b,
|
||||
double eps, int m, double *x
|
||||
) {
|
||||
int it = 0;
|
||||
double c = DBL_MAX, y, y_a = f(a), y_b = f(b);
|
||||
|
||||
if (fabs(y_a) - eps < DBL_EPSILON)
|
||||
{
|
||||
*x = a;
|
||||
return SUCCESS;
|
||||
} if (fabs(y_b) - eps < DBL_EPSILON)
|
||||
{
|
||||
*x = b;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
if (sgn_a == sgn_b)
|
||||
{
|
||||
*x = DBL_MAX;
|
||||
return MORE_ONE_ROOT;
|
||||
}
|
||||
|
||||
for (it = 0; it < m; ++it)
|
||||
{
|
||||
c = (a + b) * 0.5;
|
||||
y = f(c);
|
||||
|
||||
memcpy(&bits, &y, sizeof(bits));
|
||||
sgn_c = (bits >> 63) & 1;
|
||||
|
||||
if (fabs(y) - eps < DBL_EPSILON)
|
||||
{
|
||||
ret = SUCCESS;
|
||||
break;
|
||||
} else if ((fabs(c - a) < DBL_EPSILON) || (fabs(c - b) < DBL_EPSILON))
|
||||
{
|
||||
ret = HIGH_ERROR;
|
||||
break;
|
||||
} else if (sgn_c == sgn_a)
|
||||
{
|
||||
a = c;
|
||||
y_a = y;
|
||||
} else if (sgn_c == sgn_b)
|
||||
{
|
||||
b = c;
|
||||
y_b = y;
|
||||
}
|
||||
}
|
||||
|
||||
if (it >= m)
|
||||
ret = RUN_TIME;
|
||||
|
||||
*x = c;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
12
2025.05.02/09Ex/solve.h
Normal file
12
2025.05.02/09Ex/solve.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
#include "status.h"
|
||||
|
||||
status t1_solve (
|
||||
double (*f) (double),
|
||||
double a, double b,
|
||||
double eps, int m, double *x, int *m_it
|
||||
);
|
||||
|
||||
#endif
|
38
2025.05.02/dist/Kochubei_DS/Makefile
vendored
Normal file
38
2025.05.02/dist/Kochubei_DS/Makefile
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
OPTS = -mfpmath=sse -fstack-protector-all -W -Wall -Wextra -Wunused -Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 -Wwrite-strings -Wcast-align -Wno-long-long -std=gnu99 -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs -Wmaybe-uninitialized -Wempty-body -Wlogical-op -Wold-style-declaration -Wmissing-parameter-type -Wignored-qualifiers -Winit-self -Wshadow -Wtype-limits -Wstrict-prototypes -Wmissing-field-initializers -Wno-pointer-sign -Wswitch-default -O3 -lm
|
||||
|
||||
|
||||
all: a01.out a02.out a03.out a04.out a05.out a06.out a07.out a08.out a09.out a10.out
|
||||
|
||||
%.o: %.c
|
||||
gcc -c $(OPTS) $<
|
||||
|
||||
%.out: %.o
|
||||
gcc $(OPTS) $^ -o $@
|
||||
|
||||
solve.o: solve.c solve.h
|
||||
add.o: add.c add.h
|
||||
|
||||
a01.o: a01.c solve.h add.h
|
||||
a02.o: a02.c solve.h add.h
|
||||
a03.o: a03.c solve.h add.h
|
||||
a04.o: a04.c solve.h add.h
|
||||
a05.o: a05.c solve.h add.h
|
||||
a06.o: a06.c solve.h add.h
|
||||
a07.o: a07.c solve.h add.h
|
||||
a08.o: a08.c solve.h add.h
|
||||
a09.o: a09.c solve.h add.h
|
||||
a10.o: a10.c solve.h add.h
|
||||
|
||||
a01.out: a01.o solve.o add.o
|
||||
a02.out: a02.o solve.o add.o
|
||||
a03.out: a03.o solve.o add.o
|
||||
a04.out: a04.o solve.o add.o
|
||||
a05.out: a05.o solve.o add.o
|
||||
a06.out: a06.o solve.o add.o
|
||||
a07.out: a07.o solve.o add.o
|
||||
a08.out: a08.o solve.o add.o
|
||||
a09.out: a09.o solve.o add.o
|
||||
a10.out: a10.o solve.o add.o
|
||||
|
||||
clean:
|
||||
rm *.o *.out
|
55
2025.05.02/dist/Kochubei_DS/a01.c
vendored
Normal file
55
2025.05.02/dist/Kochubei_DS/a01.c
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include "add.h"
|
||||
#include "solve.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
double a=0;
|
||||
double b=0;
|
||||
double e=0;
|
||||
int M=0;
|
||||
int k=0;
|
||||
int res=0;
|
||||
int count=0;
|
||||
double x=0;
|
||||
double t=0;
|
||||
double (*f[7])(double) = {f0,f1,f2,f3,f4,f5,f6};
|
||||
if (argc!=6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (sscanf(argv[1], "%lf", &a)!=1 || sscanf(argv[2], "%lf", &b)!=1 || sscanf(argv[3], "%lf", &e)!=1 || sscanf(argv[4], "%d", &M)!=1 || sscanf(argv[5], "%d", &k)!=1)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (k<0 || k>6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
e=fabs(e);
|
||||
if (b<a)
|
||||
{
|
||||
double tmp=a;
|
||||
a=b;
|
||||
b=tmp;
|
||||
}
|
||||
|
||||
t=clock();
|
||||
res=solve1(f[k], a, b, e, M, &x);
|
||||
t=(clock()-t)/CLOCKS_PER_SEC;
|
||||
count=get_count();
|
||||
if (res<0)
|
||||
{
|
||||
printf ("%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], 1, count, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], 1, x, f[k](x), res, count, t);
|
||||
}
|
||||
return 0;
|
||||
}
|
48
2025.05.02/dist/Kochubei_DS/a02.c
vendored
Normal file
48
2025.05.02/dist/Kochubei_DS/a02.c
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include "add.h"
|
||||
#include "solve.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
double x0=0;
|
||||
double e=0;
|
||||
int M=0;
|
||||
int k=0;
|
||||
int count=0;
|
||||
double x=0;
|
||||
double t=0;
|
||||
int res=0;
|
||||
double (*f[7])(double) = {f0,f1,f2,f3,f4,f5,f6};
|
||||
double (*d[7])(double) = {d0,d1,d2,d3,d4,d5,d6};
|
||||
if (argc!=5)
|
||||
{
|
||||
printf("Usage: %s x0 e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (sscanf(argv[1], "%lf", &x0)!=1 || sscanf(argv[2], "%lf", &e)!=1 || sscanf(argv[3], "%d", &M)!=1 || sscanf(argv[4], "%d", &k)!=1)
|
||||
{
|
||||
printf("Usage: %s x0 e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (k<0 || k>6)
|
||||
{
|
||||
printf("Usage: %s x0 e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
e=fabs(e);
|
||||
t=clock();
|
||||
res=solve2(f[k], d[k], x0, e, M, &x);
|
||||
t=(clock()-t)/CLOCKS_PER_SEC;
|
||||
count=get_count();
|
||||
if (res<0)
|
||||
{
|
||||
printf ("%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], 2, count, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], 2, x, f[k](x), res, count, t);
|
||||
}
|
||||
return 0;
|
||||
}
|
55
2025.05.02/dist/Kochubei_DS/a03.c
vendored
Normal file
55
2025.05.02/dist/Kochubei_DS/a03.c
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include "add.h"
|
||||
#include "solve.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
double a=0;
|
||||
double b=0;
|
||||
double e=0;
|
||||
int M=0;
|
||||
int k=0;
|
||||
int res=0;
|
||||
int count=0;
|
||||
double x=0;
|
||||
double t=0;
|
||||
double (*f[7])(double) = {f0,f1,f2,f3,f4,f5,f6};
|
||||
if (argc!=6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (sscanf(argv[1], "%lf", &a)!=1 || sscanf(argv[2], "%lf", &b)!=1 || sscanf(argv[3], "%lf", &e)!=1 || sscanf(argv[4], "%d", &M)!=1 || sscanf(argv[5], "%d", &k)!=1)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (k<0 || k>6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
e=fabs(e);
|
||||
if (b<a)
|
||||
{
|
||||
double tmp=a;
|
||||
a=b;
|
||||
b=tmp;
|
||||
}
|
||||
|
||||
t=clock();
|
||||
res=solve3(f[k], a, b, e, M, &x);
|
||||
t=(clock()-t)/CLOCKS_PER_SEC;
|
||||
count=get_count();
|
||||
if (res<0)
|
||||
{
|
||||
printf ("%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], 3, count, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], 3, x, f[k](x), res, count, t);
|
||||
}
|
||||
return 0;
|
||||
}
|
55
2025.05.02/dist/Kochubei_DS/a04.c
vendored
Normal file
55
2025.05.02/dist/Kochubei_DS/a04.c
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include "add.h"
|
||||
#include "solve.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
double a=0;
|
||||
double b=0;
|
||||
double e=0;
|
||||
int M=0;
|
||||
int k=0;
|
||||
int res=0;
|
||||
int count=0;
|
||||
double x=0;
|
||||
double t=0;
|
||||
double (*f[7])(double) = {f0,f1,f2,f3,f4,f5,f6};
|
||||
if (argc!=6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (sscanf(argv[1], "%lf", &a)!=1 || sscanf(argv[2], "%lf", &b)!=1 || sscanf(argv[3], "%lf", &e)!=1 || sscanf(argv[4], "%d", &M)!=1 || sscanf(argv[5], "%d", &k)!=1)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (k<0 || k>6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
e=fabs(e);
|
||||
if (b<a)
|
||||
{
|
||||
double tmp=a;
|
||||
a=b;
|
||||
b=tmp;
|
||||
}
|
||||
|
||||
t=clock();
|
||||
res=solve4(f[k], a, b, e, M, &x);
|
||||
t=(clock()-t)/CLOCKS_PER_SEC;
|
||||
count=get_count();
|
||||
if (res<0)
|
||||
{
|
||||
printf ("%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], 4, count, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], 4, x, f[k](x), res, count, t);
|
||||
}
|
||||
return 0;
|
||||
}
|
55
2025.05.02/dist/Kochubei_DS/a05.c
vendored
Normal file
55
2025.05.02/dist/Kochubei_DS/a05.c
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include "add.h"
|
||||
#include "solve.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
double a=0;
|
||||
double b=0;
|
||||
double e=0;
|
||||
int M=0;
|
||||
int k=0;
|
||||
int res=0;
|
||||
int count=0;
|
||||
double x=0;
|
||||
double t=0;
|
||||
double (*f[7])(double) = {f0,f1,f2,f3,f4,f5,f6};
|
||||
if (argc!=6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (sscanf(argv[1], "%lf", &a)!=1 || sscanf(argv[2], "%lf", &b)!=1 || sscanf(argv[3], "%lf", &e)!=1 || sscanf(argv[4], "%d", &M)!=1 || sscanf(argv[5], "%d", &k)!=1)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (k<0 || k>6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
e=fabs(e);
|
||||
if (b<a)
|
||||
{
|
||||
double tmp=a;
|
||||
a=b;
|
||||
b=tmp;
|
||||
}
|
||||
|
||||
t=clock();
|
||||
res=solve5(f[k], a, b, e, M, &x);
|
||||
t=(clock()-t)/CLOCKS_PER_SEC;
|
||||
count=get_count();
|
||||
if (res<0)
|
||||
{
|
||||
printf ("%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], 5, count, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], 5, x, f[k](x), res, count, t);
|
||||
}
|
||||
return 0;
|
||||
}
|
64
2025.05.02/dist/Kochubei_DS/a06.c
vendored
Normal file
64
2025.05.02/dist/Kochubei_DS/a06.c
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include "add.h"
|
||||
#include "solve.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int m=0;
|
||||
double a=0;
|
||||
double b=0;
|
||||
double e=0;
|
||||
int M=0;
|
||||
int k=0;
|
||||
int res=0;
|
||||
int count=0;
|
||||
double x=0;
|
||||
double t=0;
|
||||
double* arr;
|
||||
double (*f[7])(double) = {f0,f1,f2,f3,f4,f5,f6};
|
||||
if (argc!=7)
|
||||
{
|
||||
printf("Usage: %s m[>0] a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (sscanf(argv[1], "%d", &m)!=1 || sscanf(argv[2], "%lf", &a)!=1 || sscanf(argv[3], "%lf", &b)!=1 || sscanf(argv[4], "%lf", &e)!=1 || sscanf(argv[5], "%d", &M)!=1 || sscanf(argv[6], "%d", &k)!=1)
|
||||
{
|
||||
printf("Usage: %s m[>0] a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (k<0 || k>6)
|
||||
{
|
||||
printf("Usage: %s m[>0] a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (m<0)
|
||||
{
|
||||
printf("Usage: %s m[>0] a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
e=fabs(e);
|
||||
if (b<a)
|
||||
{
|
||||
double tmp=a;
|
||||
a=b;
|
||||
b=tmp;
|
||||
}
|
||||
arr=(double*)malloc(3*(m+1)*sizeof(double));
|
||||
t=clock();
|
||||
res=solve6(f[k],m, arr, a, b, e, M, &x);
|
||||
t=(clock()-t)/CLOCKS_PER_SEC;
|
||||
count=get_count();
|
||||
if (res<0)
|
||||
{
|
||||
printf ("%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], 6, count, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], 6, x, f[k](x), res, count, t);
|
||||
}
|
||||
free(arr);
|
||||
return 0;
|
||||
}
|
47
2025.05.02/dist/Kochubei_DS/a07.c
vendored
Normal file
47
2025.05.02/dist/Kochubei_DS/a07.c
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include "add.h"
|
||||
#include "solve.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
double x0=0;
|
||||
double e=0;
|
||||
int M=0;
|
||||
int k=0;
|
||||
int count=0;
|
||||
double x=0;
|
||||
double t=0;
|
||||
int res=0;
|
||||
double (*f[7])(double) = {f0,f1,f2,f3,f4,f5,f6};
|
||||
if (argc!=5)
|
||||
{
|
||||
printf("Usage: %s x0 e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (sscanf(argv[1], "%lf", &x0)!=1 || sscanf(argv[2], "%lf", &e)!=1 || sscanf(argv[3], "%d", &M)!=1 || sscanf(argv[4], "%d", &k)!=1)
|
||||
{
|
||||
printf("Usage: %s x0 e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (k<0 || k>6)
|
||||
{
|
||||
printf("Usage: %s x0 e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
e=fabs(e);
|
||||
t=clock();
|
||||
res=solve7(f[k], x0, e, M, &x);
|
||||
t=(clock()-t)/CLOCKS_PER_SEC;
|
||||
count=get_count();
|
||||
if (res<0)
|
||||
{
|
||||
printf ("%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], 7, count, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], 7, x, f[k](x), res, count, t);
|
||||
}
|
||||
return 0;
|
||||
}
|
55
2025.05.02/dist/Kochubei_DS/a08.c
vendored
Normal file
55
2025.05.02/dist/Kochubei_DS/a08.c
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include "add.h"
|
||||
#include "solve.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
double a=0;
|
||||
double b=0;
|
||||
double e=0;
|
||||
int M=0;
|
||||
int k=0;
|
||||
int res=0;
|
||||
int count=0;
|
||||
double x=0;
|
||||
double t=0;
|
||||
double (*f[7])(double) = {f0,f1,f2,f3,f4,f5,f6};
|
||||
if (argc!=6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (sscanf(argv[1], "%lf", &a)!=1 || sscanf(argv[2], "%lf", &b)!=1 || sscanf(argv[3], "%lf", &e)!=1 || sscanf(argv[4], "%d", &M)!=1 || sscanf(argv[5], "%d", &k)!=1)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (k<0 || k>6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
e=fabs(e);
|
||||
if (b<a)
|
||||
{
|
||||
double tmp=a;
|
||||
a=b;
|
||||
b=tmp;
|
||||
}
|
||||
|
||||
t=clock();
|
||||
res=solve8(f[k], a, b, e, M, &x);
|
||||
t=(clock()-t)/CLOCKS_PER_SEC;
|
||||
count=get_count();
|
||||
if (res<0)
|
||||
{
|
||||
printf ("%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], 8, count, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], 8, x, f[k](x), res, count, t);
|
||||
}
|
||||
return 0;
|
||||
}
|
55
2025.05.02/dist/Kochubei_DS/a09.c
vendored
Normal file
55
2025.05.02/dist/Kochubei_DS/a09.c
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include "add.h"
|
||||
#include "solve.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
double a=0;
|
||||
double b=0;
|
||||
double e=0;
|
||||
int M=0;
|
||||
int k=0;
|
||||
int res=0;
|
||||
int count=0;
|
||||
double x=0;
|
||||
double t=0;
|
||||
double (*f[7])(double) = {f0,f1,f2,f3,f4,f5,f6};
|
||||
if (argc!=6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (sscanf(argv[1], "%lf", &a)!=1 || sscanf(argv[2], "%lf", &b)!=1 || sscanf(argv[3], "%lf", &e)!=1 || sscanf(argv[4], "%d", &M)!=1 || sscanf(argv[5], "%d", &k)!=1)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (k<0 || k>6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
e=fabs(e);
|
||||
if (b<a)
|
||||
{
|
||||
double tmp=a;
|
||||
a=b;
|
||||
b=tmp;
|
||||
}
|
||||
|
||||
t=clock();
|
||||
res=solve9(f[k], a, b, e, M, &x);
|
||||
t=(clock()-t)/CLOCKS_PER_SEC;
|
||||
count=get_count();
|
||||
if (res<0)
|
||||
{
|
||||
printf ("%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], 9, count, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], 9, x, f[k](x), res, count, t);
|
||||
}
|
||||
return 0;
|
||||
}
|
55
2025.05.02/dist/Kochubei_DS/a10.c
vendored
Normal file
55
2025.05.02/dist/Kochubei_DS/a10.c
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include "add.h"
|
||||
#include "solve.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
double a=0;
|
||||
double b=0;
|
||||
double e=0;
|
||||
int M=0;
|
||||
int k=0;
|
||||
int res=0;
|
||||
int count=0;
|
||||
double x=0;
|
||||
double t=0;
|
||||
double (*f[7])(double) = {f0,f1,f2,f3,f4,f5,f6};
|
||||
if (argc!=6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (sscanf(argv[1], "%lf", &a)!=1 || sscanf(argv[2], "%lf", &b)!=1 || sscanf(argv[3], "%lf", &e)!=1 || sscanf(argv[4], "%d", &M)!=1 || sscanf(argv[5], "%d", &k)!=1)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (k<0 || k>6)
|
||||
{
|
||||
printf("Usage: %s a b e[>0] M[>0] k[0-6]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
e=fabs(e);
|
||||
if (b<a)
|
||||
{
|
||||
double tmp=a;
|
||||
a=b;
|
||||
b=tmp;
|
||||
}
|
||||
|
||||
t=clock();
|
||||
res=solve10(f[k], a, b, e, M, &x);
|
||||
t=(clock()-t)/CLOCKS_PER_SEC;
|
||||
count=get_count();
|
||||
if (res<0)
|
||||
{
|
||||
printf ("%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], 10, count, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], 10, x, f[k](x), res, count, t);
|
||||
}
|
||||
return 0;
|
||||
}
|
167
2025.05.02/dist/Kochubei_DS/add.c
vendored
Normal file
167
2025.05.02/dist/Kochubei_DS/add.c
vendored
Normal file
|
@ -0,0 +1,167 @@
|
|||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "add.h"
|
||||
|
||||
static unsigned int count=0;
|
||||
|
||||
inline unsigned int get_count(void)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
double f0(double x)
|
||||
{
|
||||
(void)x;
|
||||
count++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
double f1(double x)
|
||||
{
|
||||
count++;
|
||||
return x-1e100;
|
||||
}
|
||||
|
||||
double f2(double x)
|
||||
{
|
||||
count++;
|
||||
return 4-x*x;
|
||||
}
|
||||
|
||||
double f3(double x)
|
||||
{
|
||||
count++;
|
||||
return x*x*x+3*x*x+16;
|
||||
}
|
||||
|
||||
double f4(double x)
|
||||
{
|
||||
count++;
|
||||
return 3-2*x*x-x*x*x*x;
|
||||
}
|
||||
|
||||
double f5(double x)
|
||||
{
|
||||
count++;
|
||||
return sqrt(fabs(x)+1)-2;
|
||||
}
|
||||
|
||||
double f6(double x)
|
||||
{
|
||||
count++;
|
||||
return sqrt(sqrt(fabs(x)+1)+1)-2;
|
||||
}
|
||||
|
||||
double d0(double x)
|
||||
{
|
||||
(void)x;
|
||||
return 0;
|
||||
}
|
||||
|
||||
double d1(double x)
|
||||
{
|
||||
(void)x;
|
||||
return 1;
|
||||
}
|
||||
|
||||
double d2(double x)
|
||||
{
|
||||
return -2*x;
|
||||
}
|
||||
|
||||
double d3(double x)
|
||||
{
|
||||
return 3*x*x+6*x;
|
||||
}
|
||||
|
||||
double d4(double x)
|
||||
{
|
||||
return -4*x-4*x*x*x;
|
||||
}
|
||||
|
||||
double d5(double x)
|
||||
{
|
||||
if (x>0)
|
||||
{
|
||||
return 1.0/2.0/sqrt(x+1);
|
||||
}
|
||||
else if (eq(x,0))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1.0/2.0/sqrt(1-x);
|
||||
}
|
||||
}
|
||||
|
||||
double d6(double x)
|
||||
{
|
||||
if (x>0)
|
||||
{
|
||||
double r=sqrt(x+1);
|
||||
return 1.0/4.0/sqrt(r+1)/r;
|
||||
}
|
||||
else if (eq(x,0))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
double r=sqrt(1-x);
|
||||
return 1.0/4.0/sqrt(r+1)/r;
|
||||
}
|
||||
}
|
||||
|
||||
inline int eq(double a, double b)
|
||||
{
|
||||
long long int A=0;
|
||||
long long int B=0;
|
||||
memcpy(&A, &a, sizeof(a));
|
||||
memcpy(&B, &b, sizeof(b));
|
||||
return (A==B);
|
||||
}
|
||||
|
||||
inline int sign_eq(double a, double b)
|
||||
{
|
||||
return (a>0 && b>0) || (a<0 && b<0);
|
||||
}
|
||||
inline int newton(double x, int n, double* a, double* b, double* ans)
|
||||
{
|
||||
double res=0;
|
||||
for (int j=0; j<n; j++)
|
||||
{
|
||||
for (int i=n-1; i>j; i--)
|
||||
{
|
||||
double dif=a[i]-a[i-j-1];
|
||||
if (eq(dif,0))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
b[i]=(b[i]-b[i - 1])/dif;
|
||||
}
|
||||
}
|
||||
for (int i=n-1; i>=0; i--)
|
||||
{
|
||||
res=res*(x-a[i])+b[i];
|
||||
}
|
||||
*ans=res;
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void parabola(double x1, double x2, double x3, double y1, double y2, double y3, double* A, double* B, double* C)
|
||||
{
|
||||
double V=(x1-x2)*(x1-x3)*(x2-x3);
|
||||
if (eq(x1,x2) || eq(x2,x3) || eq(x3,x1))
|
||||
{
|
||||
*A=0;
|
||||
*B=0;
|
||||
*C=0;
|
||||
return;
|
||||
}
|
||||
*A=(y1*x2-y1*x3-y2*x1+y3*x1+y2*x3-y3*x2)/V;
|
||||
*B=(x2*x2*y3-x3*x3*y2-x1*x1*y3+x3*x3*y1+x1*x1*y2-x2*x2*y1)/V;
|
||||
*C=(y1*x2*x3*(x2-x3)-y2*x1*x3*(x1-x3)+y3*x1*x2*(x1-x2))/V;
|
||||
return;
|
||||
}
|
37
2025.05.02/dist/Kochubei_DS/add.h
vendored
Normal file
37
2025.05.02/dist/Kochubei_DS/add.h
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
double f0(double x);
|
||||
|
||||
double f1(double x);
|
||||
|
||||
double f2(double x);
|
||||
|
||||
double f3(double x);
|
||||
|
||||
double f4(double x);
|
||||
|
||||
double f5(double x);
|
||||
|
||||
double f6(double x);
|
||||
|
||||
double d0(double x);
|
||||
|
||||
double d1(double x);
|
||||
|
||||
double d2(double x);
|
||||
|
||||
double d3(double x);
|
||||
|
||||
double d4(double x);
|
||||
|
||||
double d5(double x);
|
||||
|
||||
double d6(double x);
|
||||
|
||||
int eq(double a, double b);
|
||||
|
||||
int sign_eq(double a, double b);
|
||||
|
||||
int newton(double x, int n, double* a, double* b, double* ans);
|
||||
|
||||
unsigned int get_count(void);
|
||||
|
||||
void parabola(double x1, double x2, double x3, double y1, double y2, double y3, double* A, double* B, double* C);
|
515
2025.05.02/dist/Kochubei_DS/solve.c
vendored
Normal file
515
2025.05.02/dist/Kochubei_DS/solve.c
vendored
Normal file
|
@ -0,0 +1,515 @@
|
|||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include "add.h"
|
||||
#include "solve.h"
|
||||
|
||||
inline int solve1(double (*f) (double), double a, double b, double e, int M, double* x)
|
||||
{
|
||||
double y1=0;
|
||||
double y2=0;
|
||||
if (eq(a,b))
|
||||
{
|
||||
if (f(a)<e)
|
||||
{
|
||||
*x=a;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
y1=f(a);
|
||||
y2=f(b);
|
||||
for (int i=0; i<M; i++)
|
||||
{
|
||||
if (sign_eq(y1, y2))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
double c=(a+b)/2;
|
||||
double y3=f(c);
|
||||
if (fabs(y3)<e)
|
||||
{
|
||||
*x=c;
|
||||
return i;
|
||||
}
|
||||
if (sign_eq(y1, y3))
|
||||
{
|
||||
a=c;
|
||||
y1=y3;
|
||||
}
|
||||
else
|
||||
{
|
||||
b=c;
|
||||
y2=y3;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int solve2(double (*f) (double), double (*d) (double), double x0, double e, int M, double* x)
|
||||
{
|
||||
double y=f(x0);
|
||||
for (int i=0; i<M; i++)
|
||||
{
|
||||
double y_new=0;
|
||||
if (fabs(y)<e)
|
||||
{
|
||||
*x=x0;
|
||||
return i;
|
||||
}
|
||||
if (eq(d(x0), 0))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
x0=x0-y/d(x0);
|
||||
y_new=f(x0);
|
||||
/*/
|
||||
if (fabs(y_new)>fabs(y))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
/*/
|
||||
y=y_new;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int solve3(double (*f) (double), double a, double b, double e, int M, double* x)
|
||||
{
|
||||
double y1=0;
|
||||
double y2=0;
|
||||
if (eq(a,b))
|
||||
{
|
||||
if (f(a)<e)
|
||||
{
|
||||
*x=a;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
y1=f(a);
|
||||
y2=f(b);
|
||||
if (sign_eq(y1, y2))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int i=0; i<M; i++)
|
||||
{
|
||||
double c=0;
|
||||
double y3=0;
|
||||
if (eq(y1,y2))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
c=a-(b-a)*y1/(y2-y1);
|
||||
y3=f(c);
|
||||
if (fabs(y3)<e)
|
||||
{
|
||||
*x=c;
|
||||
return i;
|
||||
}
|
||||
if (sign_eq(y1, y3))
|
||||
{
|
||||
a=c;
|
||||
y1=y3;
|
||||
}
|
||||
else
|
||||
{
|
||||
b=c;
|
||||
y2=y3;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int solve4(double (*f) (double), double a, double b, double e, int M, double* x)
|
||||
{
|
||||
double y1=0;
|
||||
double y2=0;
|
||||
if (eq(a,b))
|
||||
{
|
||||
if (f(a)<e)
|
||||
{
|
||||
*x=a;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
y1=f(a);
|
||||
y2=f(b);
|
||||
for (int i=0; i<M; i++)
|
||||
{
|
||||
double c=0;
|
||||
double y3=0;
|
||||
c=a-(b-a)*y1/(y2-y1);
|
||||
y3=f(c);
|
||||
if (fabs(y3)<e)
|
||||
{
|
||||
*x=c;
|
||||
return i;
|
||||
}
|
||||
if (c>a && c>b)
|
||||
{
|
||||
a=b;
|
||||
y1=y2;
|
||||
b=c;
|
||||
y2=y3;
|
||||
}
|
||||
else if (c<a && c<b)
|
||||
{
|
||||
b=a;
|
||||
y2=y1;
|
||||
a=c;
|
||||
y1=y3;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fabs(a-c)<=fabs(b-c))
|
||||
{
|
||||
a=c;
|
||||
y1=y3;
|
||||
}
|
||||
else
|
||||
{
|
||||
b=c;
|
||||
y2=y3;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int solve5(double (*f) (double), double a, double b, double e, int M, double* x)
|
||||
{
|
||||
double y1=0;
|
||||
double y2=0;
|
||||
if (eq(a,b))
|
||||
{
|
||||
if (f(a)<e)
|
||||
{
|
||||
*x=a;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
y1=f(a);
|
||||
y2=f(b);
|
||||
for (int i=0; i<M; i++)
|
||||
{
|
||||
double c=0;
|
||||
double y3=0;
|
||||
double X[3];
|
||||
double Y[3];
|
||||
double p=0;
|
||||
double y_p=0;
|
||||
c=(a+b)/2;
|
||||
y3=f(c);
|
||||
X[0]=y1;
|
||||
X[1]=y3;
|
||||
X[2]=y2;
|
||||
Y[0]=a;
|
||||
Y[1]=c;
|
||||
Y[2]=b;
|
||||
if (newton(0, 3, X, Y, &p)==-1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
y_p=f(p);
|
||||
if (fabs(y_p)<e)
|
||||
{
|
||||
*x=p;
|
||||
return i;
|
||||
}
|
||||
if (p<a)
|
||||
{
|
||||
b=a;
|
||||
y2=y1;
|
||||
a=p;
|
||||
y1=y_p;
|
||||
}
|
||||
else if (p>=a && p<=c)
|
||||
{
|
||||
a=p;
|
||||
y1=y_p;
|
||||
b=c;
|
||||
y2=y3;
|
||||
}
|
||||
else if (p<=c && p<=b)
|
||||
{
|
||||
a=c;
|
||||
y1=y3;
|
||||
b=p;
|
||||
y2=y_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
a=b;
|
||||
y1=y2;
|
||||
b=p;
|
||||
y2=y_p;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int solve6(double (*f) (double), int m, double* d, double a, double b, double e, int M, double *x)
|
||||
{
|
||||
double y1=0;
|
||||
double y2=0;
|
||||
if (m<1) return -1;
|
||||
if (eq(a,b))
|
||||
{
|
||||
if (f(a)<e)
|
||||
{
|
||||
*x=a;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
y1=f(a);
|
||||
y2=f(b);
|
||||
for (int i=0; i<M; i++)
|
||||
{
|
||||
double p=0;
|
||||
double y_p=0;
|
||||
double h=(b-a)/m;
|
||||
d[0]=a;
|
||||
d[m+1]=y1;
|
||||
d[2*(m+1)]=y1;
|
||||
d[m]=b;
|
||||
d[m+(m+1)]=y2;
|
||||
d[m+2*(m+1)]=y2;
|
||||
for (int j=1; j<m; j++)
|
||||
{
|
||||
double t=f(a+j*h);
|
||||
d[j]=a+j*h;
|
||||
d[j+(m+1)]=t;
|
||||
d[j+2*(m+1)]=t;
|
||||
}
|
||||
if (newton(0, m+1, d+(m+1), d, &p)==-1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
y_p=f(p);
|
||||
for (int j=0; j<m+1; j++)
|
||||
{
|
||||
d[j+(m+1)]=d[j+2*(m+1)];
|
||||
}
|
||||
if (fabs(y_p)<e)
|
||||
{
|
||||
*x=p;
|
||||
return i;
|
||||
}
|
||||
if (p<a)
|
||||
{
|
||||
b=a;
|
||||
y2=y1;
|
||||
a=p;
|
||||
y1=y_p;
|
||||
}
|
||||
else if (p>b)
|
||||
{
|
||||
a=b;
|
||||
y1=y2;
|
||||
b=p;
|
||||
y2=y_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
int pos=(p-a)/h;
|
||||
a=a+pos*h;
|
||||
y1=d[pos+(m+1)];
|
||||
b=a+(pos+1)*h;
|
||||
y2=d[pos+1+(m+1)];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int solve7(double (*f) (double), double x0, double e, int M, double* x)
|
||||
{
|
||||
double last_x0=1e300;
|
||||
for (int i=0; i<M; i++)
|
||||
{
|
||||
double y=f(x0);
|
||||
if (fabs(y-x0)>fabs(x0-last_x0))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (fabs(y-x0)<e)
|
||||
{
|
||||
*x=x0;
|
||||
return i;
|
||||
}
|
||||
last_x0=x0;
|
||||
x0=y;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int solve8(double (*f) (double), double a, double b, double e, int M, double* x)
|
||||
{
|
||||
double y1=0;
|
||||
double y2=0;
|
||||
if (eq(a,b))
|
||||
{
|
||||
*x=a;
|
||||
return 0;
|
||||
}
|
||||
y2=f(a);
|
||||
for (int i=0; i<M; i++)
|
||||
{
|
||||
double h=(b-a)/16;
|
||||
int was_break=0;
|
||||
for (int j=0; j<15; j++)
|
||||
{
|
||||
y1=y2;
|
||||
y2=f(a+(j+1)*h);
|
||||
if (y2<y1)
|
||||
{
|
||||
b=(a+j*h);
|
||||
a=(a+(j+1)*h);
|
||||
was_break=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (was_break==0)
|
||||
{
|
||||
a=a+15*h;
|
||||
}
|
||||
if (fabs(b-a)<e)
|
||||
{
|
||||
*x=(b+a)/2;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int solve9(double (*f) (double), double a, double b, double e, int M, double* x)
|
||||
{
|
||||
double phi=(1+sqrt(5))/2;
|
||||
double y1=0;
|
||||
double y2=0;
|
||||
double x1=b-(b-a)/phi;
|
||||
double x2=a+(b-a)/phi;
|
||||
if (eq(a,b))
|
||||
{
|
||||
*x=a;
|
||||
return 0;
|
||||
}
|
||||
y1=f(x1);
|
||||
y2=f(x2);
|
||||
for (int i=0; i<M; i++)
|
||||
{
|
||||
if (y1<=y2)
|
||||
{
|
||||
a=x1;
|
||||
y1=y2;
|
||||
x1=b-(b-a)/phi;
|
||||
x2=a+(b-a)/phi;
|
||||
y2=f(x2);
|
||||
}
|
||||
else
|
||||
{
|
||||
b=x2;
|
||||
y2=y1;
|
||||
x1=b-(b-a)/phi;
|
||||
x2=a+(b-a)/phi;
|
||||
y1=f(x1);
|
||||
}
|
||||
if (b-a<e)
|
||||
{
|
||||
*x=(b+a)/2;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int solve10(double (*f) (double), double a, double b, double e, int M, double *x)
|
||||
{
|
||||
double y1=0;
|
||||
double y2=0;
|
||||
if (eq(a,b))
|
||||
{
|
||||
*x=a;
|
||||
return 0;
|
||||
}
|
||||
y1=f(a);
|
||||
y2=f(b);
|
||||
for (int i=0; i<M; i++)
|
||||
{
|
||||
double c=(a+b)/2;
|
||||
double y_c=f(c);
|
||||
double A=0;
|
||||
double B=0;
|
||||
double C=0;
|
||||
double x_max=0;
|
||||
double y_max=0;
|
||||
parabola(a,c,b,y1,y_c,y2, &A, &B, &C);
|
||||
if (A>=0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
x_max=-B/2/A;
|
||||
y_max=f(x_max);
|
||||
if (x_max<a)
|
||||
{
|
||||
b=a;
|
||||
y2=y1;
|
||||
a=x_max;
|
||||
y1=y_max;
|
||||
}
|
||||
else if (x_max>a && x_max<c)
|
||||
{
|
||||
a=x_max;
|
||||
y1=y_max;
|
||||
b=c;
|
||||
y2=y_c;
|
||||
}
|
||||
else if (x_max>c && x_max<b)
|
||||
{
|
||||
a=c;
|
||||
y1=y_c;
|
||||
b=x_max;
|
||||
y2=y_max;
|
||||
}
|
||||
else if (x_max>b)
|
||||
{
|
||||
a=b;
|
||||
y1=y2;
|
||||
b=x_max;
|
||||
y2=y_max;
|
||||
}
|
||||
else
|
||||
{
|
||||
*x=x_max;
|
||||
return i;
|
||||
}
|
||||
if (b-a<e)
|
||||
{
|
||||
*x=x_max;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
19
2025.05.02/dist/Kochubei_DS/solve.h
vendored
Normal file
19
2025.05.02/dist/Kochubei_DS/solve.h
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
int solve1(double (*f) (double), double a, double b, double e, int M, double* x);
|
||||
|
||||
int solve2(double (*f) (double), double (*d) (double), double x0, double e, int M, double* x);
|
||||
|
||||
int solve3(double (*f) (double), double a, double b, double e, int M, double* x);
|
||||
|
||||
int solve4(double (*f) (double), double a, double b, double e, int M, double* x);
|
||||
|
||||
int solve5(double (*f) (double), double a, double b, double e, int M, double* x);
|
||||
|
||||
int solve6(double (*f) (double), int m, double* d, double a, double b, double e, int M, double *x);
|
||||
|
||||
int solve7(double (*f) (double), double x0, double e, int M, double* x);
|
||||
|
||||
int solve8(double (*f) (double), double a, double b, double e, int M, double* x);
|
||||
|
||||
int solve9(double (*f) (double), double a, double b, double e, int M, double* x);
|
||||
|
||||
int solve10(double (*f) (double), double a, double b, double e, int M, double *x);
|
Loading…
Add table
Add a link
Reference in a new issue