Task 1 and 2 are done!
This commit is contained in:
parent
cdc405551d
commit
a39f0f19e3
20 changed files with 587 additions and 0 deletions
18
2025.05.02/tests/2nd_must_find_test.sh
Executable file
18
2025.05.02/tests/2nd_must_find_test.sh
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
script_name="$(basename "$0")"
|
||||||
|
iter="1000"
|
||||||
|
mkdir -p tests
|
||||||
|
|
||||||
|
if [ "$#" -ne 2 ]; then
|
||||||
|
echo "The number of parameters is less than 2"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
for (( k = 3 ; k < 7; k++ )); do
|
||||||
|
echo "------- K = $k -------"
|
||||||
|
for (( a = -100 ; a < 100 ; a++ )); do
|
||||||
|
echo "k = $k x_0 = "$(echo "$a / 10" | bc -l)" Iter = $iter ---"
|
||||||
|
./a0$1.out "$(echo "$a / 10" | bc -l)" 1e-16 $iter $k
|
||||||
|
done
|
||||||
|
done >$(pwd)/tests/out_$script_name.log 2>$(pwd)/tests/err_$script_name.log
|
42
2025.05.09/01Ex/Makefile
Normal file
42
2025.05.09/01Ex/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 = a01.$(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.09/01Ex/init_f.c
Normal file
61
2025.05.09/01Ex/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 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double f2 (double x)
|
||||||
|
{
|
||||||
|
cl++;
|
||||||
|
return x * x + x + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double f3 (double x)
|
||||||
|
{
|
||||||
|
double x_2 = x * x;
|
||||||
|
cl++;
|
||||||
|
|
||||||
|
return x * x_2 + x_2 + x + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double f4 (double x)
|
||||||
|
{
|
||||||
|
double x_2 = x * x;
|
||||||
|
double x_3 = x_2 * x;
|
||||||
|
cl++;
|
||||||
|
|
||||||
|
return x * x_3 + x_3 + x_2 + x + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double f5 (double x)
|
||||||
|
{
|
||||||
|
cl++;
|
||||||
|
return exp(-x);
|
||||||
|
}
|
||||||
|
|
||||||
|
double f6 (double x)
|
||||||
|
{
|
||||||
|
cl++;
|
||||||
|
return 1 / (25 * x * x + 1);
|
||||||
|
}
|
||||||
|
|
13
2025.05.09/01Ex/init_f.h
Normal file
13
2025.05.09/01Ex/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
|
45
2025.05.09/01Ex/main.c
Normal file
45
2025.05.09/01Ex/main.c
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"
|
||||||
|
|
||||||
|
/* ./a01.out x h k */
|
||||||
|
int main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
double t, x, h, d;
|
||||||
|
int k, cl, task = 1;
|
||||||
|
|
||||||
|
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", &x) == 1 &&
|
||||||
|
((sscanf(argv[2], "%lf", &h) == 1) && (h > 0)) &&
|
||||||
|
((sscanf(argv[3], "%d", &k) == 1) && ((0 <= k) && (k <= len_f))))
|
||||||
|
) {
|
||||||
|
fprintf(stderr, "Usage: %s x h k\n", argv[0]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
t = clock();
|
||||||
|
d = t1_solve(f_lst[k], x, h);
|
||||||
|
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
cl = get_call_count();
|
||||||
|
|
||||||
|
if (fabs(d - DBL_MAX) < DBL_EPSILON)
|
||||||
|
{
|
||||||
|
fprintf (stdout, "%s : Task = %d Method is not applicable Count = %d T = %.2f\n", argv[0], task, cl, t);
|
||||||
|
return -2;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
fprintf (stdout, "%s : Task = %d Res = %e Count = %d T = %.2f\n", argv[0], task, d, cl, t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
14
2025.05.09/01Ex/solve.c
Normal file
14
2025.05.09/01Ex/solve.c
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#include "solve.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
int t1_solve (
|
||||||
|
double (*f) (double),
|
||||||
|
double x, double h
|
||||||
|
) {
|
||||||
|
if (h < DBL_EPSILON)
|
||||||
|
return DBL_MAX;
|
||||||
|
return (f(x + h) - f(x)) / h;
|
||||||
|
}
|
||||||
|
|
9
2025.05.09/01Ex/solve.h
Normal file
9
2025.05.09/01Ex/solve.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef SOLVE_H
|
||||||
|
#define SOLVE_H
|
||||||
|
|
||||||
|
int t1_solve (
|
||||||
|
double (*f) (double),
|
||||||
|
double x, double h
|
||||||
|
);
|
||||||
|
|
||||||
|
#endif
|
42
2025.05.09/02Ex/Makefile
Normal file
42
2025.05.09/02Ex/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 = a02.$(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.09/02Ex/init_f.c
Normal file
61
2025.05.09/02Ex/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 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double f2 (double x)
|
||||||
|
{
|
||||||
|
cl++;
|
||||||
|
return x * x + x + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double f3 (double x)
|
||||||
|
{
|
||||||
|
double x_2 = x * x;
|
||||||
|
cl++;
|
||||||
|
|
||||||
|
return x * x_2 + x_2 + x + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double f4 (double x)
|
||||||
|
{
|
||||||
|
double x_2 = x * x;
|
||||||
|
double x_3 = x_2 * x;
|
||||||
|
cl++;
|
||||||
|
|
||||||
|
return x * x_3 + x_3 + x_2 + x + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double f5 (double x)
|
||||||
|
{
|
||||||
|
cl++;
|
||||||
|
return exp(-x);
|
||||||
|
}
|
||||||
|
|
||||||
|
double f6 (double x)
|
||||||
|
{
|
||||||
|
cl++;
|
||||||
|
return 1 / (25 * x * x + 1);
|
||||||
|
}
|
||||||
|
|
13
2025.05.09/02Ex/init_f.h
Normal file
13
2025.05.09/02Ex/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
|
45
2025.05.09/02Ex/main.c
Normal file
45
2025.05.09/02Ex/main.c
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"
|
||||||
|
|
||||||
|
/* ./a02.out x h k */
|
||||||
|
int main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
double t, x, h, d;
|
||||||
|
int k, cl, task = 2;
|
||||||
|
|
||||||
|
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", &x) == 1 &&
|
||||||
|
((sscanf(argv[2], "%lf", &h) == 1) && (h > 0)) &&
|
||||||
|
((sscanf(argv[3], "%d", &k) == 1) && ((0 <= k) && (k <= len_f))))
|
||||||
|
) {
|
||||||
|
fprintf(stderr, "Usage: %s x h k\n", argv[0]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
t = clock();
|
||||||
|
d = t2_solve(f_lst[k], x, h);
|
||||||
|
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
cl = get_call_count();
|
||||||
|
|
||||||
|
if (fabs(d - DBL_MAX) < DBL_EPSILON)
|
||||||
|
{
|
||||||
|
fprintf (stdout, "%s : Task = %d Method is not applicable Count = %d T = %.2f\n", argv[0], task, cl, t);
|
||||||
|
return -2;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
fprintf (stdout, "%s : Task = %d Res = %e Count = %d T = %.2f\n", argv[0], task, d, cl, t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
14
2025.05.09/02Ex/solve.c
Normal file
14
2025.05.09/02Ex/solve.c
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#include "solve.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
int t2_solve (
|
||||||
|
double (*f) (double),
|
||||||
|
double x, double h
|
||||||
|
) {
|
||||||
|
if (h < DBL_EPSILON)
|
||||||
|
return DBL_MAX;
|
||||||
|
return (f(x + h) - f(x - h)) / (2 * h);
|
||||||
|
}
|
||||||
|
|
9
2025.05.09/02Ex/solve.h
Normal file
9
2025.05.09/02Ex/solve.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef SOLVE_H
|
||||||
|
#define SOLVE_H
|
||||||
|
|
||||||
|
int t2_solve (
|
||||||
|
double (*f) (double),
|
||||||
|
double x, double h
|
||||||
|
);
|
||||||
|
|
||||||
|
#endif
|
42
2025.05.09/Example/Makefile
Normal file
42
2025.05.09/Example/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 = a01.$(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.09/Example/init_f.c
Normal file
61
2025.05.09/Example/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 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double f2 (double x)
|
||||||
|
{
|
||||||
|
cl++;
|
||||||
|
return x * x + x + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double f3 (double x)
|
||||||
|
{
|
||||||
|
double x_2 = x * x;
|
||||||
|
cl++;
|
||||||
|
|
||||||
|
return x * x_2 + x_2 + x + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double f4 (double x)
|
||||||
|
{
|
||||||
|
double x_2 = x * x;
|
||||||
|
double x_3 = x_2 * x;
|
||||||
|
cl++;
|
||||||
|
|
||||||
|
return x * x_3 + x_3 + x_2 + x + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double f5 (double x)
|
||||||
|
{
|
||||||
|
cl++;
|
||||||
|
return exp(-x);
|
||||||
|
}
|
||||||
|
|
||||||
|
double f6 (double x)
|
||||||
|
{
|
||||||
|
cl++;
|
||||||
|
return 1 / (25 * x * x + 1);
|
||||||
|
}
|
||||||
|
|
13
2025.05.09/Example/init_f.h
Normal file
13
2025.05.09/Example/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
|
45
2025.05.09/Example/main.c
Normal file
45
2025.05.09/Example/main.c
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"
|
||||||
|
|
||||||
|
/* ./a01.out x h k */
|
||||||
|
int main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
double t, x, h, d;
|
||||||
|
int k, cl, task = 1;
|
||||||
|
|
||||||
|
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", &x) == 1 &&
|
||||||
|
((sscanf(argv[2], "%lf", &h) == 1) && (h > 0)) &&
|
||||||
|
((sscanf(argv[3], "%d", &k) == 1) && ((0 <= k) && (k <= len_f))))
|
||||||
|
) {
|
||||||
|
fprintf(stderr, "Usage: %s x h k\n", argv[0]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
t = clock();
|
||||||
|
d = t1_solve(f_lst[k], x, h);
|
||||||
|
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
cl = get_call_count();
|
||||||
|
|
||||||
|
if (fabs(d - DBL_MAX) < DBL_EPSILON)
|
||||||
|
{
|
||||||
|
fprintf (stdout, "%s : Task = %d Method is not applicable Count = %d T = %.2f\n", argv[0], task, cl, t);
|
||||||
|
return -2;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
fprintf (stdout, "%s : Task = %d Res = %e Count = %d T = %.2f\n", argv[0], task, d, cl, t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
14
2025.05.09/Example/solve.c
Normal file
14
2025.05.09/Example/solve.c
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#include "solve.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
int t1_solve (
|
||||||
|
double (*f) (double),
|
||||||
|
double x, double h
|
||||||
|
) {
|
||||||
|
if (h < DBL_EPSILON)
|
||||||
|
return DBL_MAX;
|
||||||
|
return (f(x + h) - f(x)) / h;
|
||||||
|
}
|
||||||
|
|
9
2025.05.09/Example/solve.h
Normal file
9
2025.05.09/Example/solve.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef SOLVE_H
|
||||||
|
#define SOLVE_H
|
||||||
|
|
||||||
|
int t1_solve (
|
||||||
|
double (*f) (double),
|
||||||
|
double x, double h
|
||||||
|
);
|
||||||
|
|
||||||
|
#endif
|
17
2025.05.09/tests/2nd_must_find_test.sh
Executable file
17
2025.05.09/tests/2nd_must_find_test.sh
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
script_name="$(basename "$0")"
|
||||||
|
mkdir -p tests
|
||||||
|
|
||||||
|
if [ "$#" -ne 1 ]; then
|
||||||
|
echo "The number of parameters is not equal 1"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
for (( k = 0 ; k < 7; k++ )); do
|
||||||
|
echo "------- K = $k -------"
|
||||||
|
for (( a = -100 ; a < 100 ; a++ )); do
|
||||||
|
echo "k = $k x_0 = "$(echo "$a / 10" | bc -l)" ---"
|
||||||
|
./a0$1.out "$(echo "$a / 10" | bc -l)" 1e-14 $k
|
||||||
|
done
|
||||||
|
done >$(pwd)/tests/out_$script_name.log 2>$(pwd)/tests/err_$script_name.log
|
Loading…
Add table
Add a link
Reference in a new issue