Task 1 was done!
This commit is contained in:
parent
768df4b636
commit
9319f68a39
71 changed files with 249 additions and 166 deletions
BIN
2025.04.04/asymptotics_test/asymptotics.xlsx
Normal file
BIN
2025.04.04/asymptotics_test/asymptotics.xlsx
Normal file
Binary file not shown.
Binary file not shown.
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 1.890e-15 -4.851e-16
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 4.820e-27
|
|
||||||
1.110e-16 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
-2.220e-16 -1.332e-15 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 4.725103e-09 Res2 = 5.398199e-10 Elapsed = 0.78 K = 2 N = 1000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 -1.787e-15 4.055e-16
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 -4.626e-25
|
|
||||||
2.866e-27 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
1.018e-28 -4.441e-16 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 2.747140e-08 Res2 = 2.397914e-09 Elapsed = 8.07 K = 2 N = 2000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 1.264e-15 2.400e-15
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 -4.996e-16
|
|
||||||
2.220e-16 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
5.551e-17 2.220e-16 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 8.237660e-08 Res2 = 4.537065e-09 Elapsed = 26.56 K = 2 N = 3000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 -2.785e-16 3.760e-15
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 -5.551e-17
|
|
||||||
4.441e-16 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
1.249e-16 -4.718e-16 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 1.618474e-07 Res2 = 9.359467e-09 Elapsed = 64.23 K = 2 N = 4000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 -8.688e-16 3.613e-15
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 5.551e-17
|
|
||||||
3.886e-16 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
-8.419e-16 8.882e-16 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 0.000000e+00 Res2 = 0.000000e+00 Elapsed = 125.04 K = 2 N = 5000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 1.008e-15 1.178e-15
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 -8.327e-17
|
|
||||||
1.117e-27 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
9.252e-17 -2.591e-16 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 0.000000e+00 Res2 = 0.000000e+00 Elapsed = 218.34 K = 2 N = 6000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 1.023e-15 1.463e-15
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 -1.527e-15
|
|
||||||
-2.776e-16 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
-3.701e-17 5.181e-16 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 0.000000e+00 Res2 = 0.000000e+00 Elapsed = 341.54 K = 2 N = 7000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 5.577e-16 -5.966e-16
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 -6.106e-16
|
|
||||||
-5.476e-24 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
-2.498e-16 1.665e-16 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 0.000000e+00 Res2 = 0.000000e+00 Elapsed = 511.43 K = 2 N = 8000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 -1.369e-16 -2.453e-15
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 -1.277e-15
|
|
||||||
4.441e-16 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
-2.961e-16 -1.134e-23 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 0.000000e+00 Res2 = 0.000000e+00 Elapsed = 728.62 K = 2 N = 9000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 2.090e-15 -1.853e-15
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 7.772e-16
|
|
||||||
3.886e-16 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
-2.553e-27 -3.331e-16 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 0.000000e+00 Res2 = 0.000000e+00 Elapsed = 1007.83 K = 2 N = 10000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 -5.878e-16 2.292e-15
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 -9.576e-16
|
|
||||||
1.110e-16 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
3.886e-16 1.110e-16 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 0.000000e+00 Res2 = 0.000000e+00 Elapsed = 1330.51 K = 2 N = 11000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 -5.274e-15 1.485e-15
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 -8.327e-17
|
|
||||||
2.220e-16 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
-4.441e-16 -4.441e-16 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 0.000000e+00 Res2 = 0.000000e+00 Elapsed = 1718.64 K = 2 N = 12000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 -5.159e-15 -9.207e-17
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 -4.441e-16
|
|
||||||
-2.220e-16 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
2.220e-16 -2.220e-16 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 0.000000e+00 Res2 = 0.000000e+00 Elapsed = 2181.13 K = 2 N = 13000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 -4.055e-15 2.933e-15
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 -8.882e-16
|
|
||||||
6.106e-16 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
-1.110e-16 2.206e-26 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 0.000000e+00 Res2 = 0.000000e+00 Elapsed = 2731.38 K = 2 N = 14000
|
|
|
@ -1,11 +0,0 @@
|
||||||
Initial matrix:
|
|
||||||
1.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
2.000e+00 2.000e+00 3.000e+00 4.000e+00
|
|
||||||
3.000e+00 3.000e+00 3.000e+00 4.000e+00
|
|
||||||
4.000e+00 4.000e+00 4.000e+00 4.000e+00
|
|
||||||
Inverse matrix:
|
|
||||||
-1.000e+00 1.000e+00 -4.133e-16 6.973e-15
|
|
||||||
1.000e+00 -2.000e+00 1.000e+00 -3.331e-16
|
|
||||||
9.992e-16 1.000e+00 -2.000e+00 1.000e+00
|
|
||||||
-8.882e-16 2.220e-15 1.000e+00 -2.000e+00
|
|
||||||
./a.out : Task = 14 Res1 = 0.000000e+00 Res2 = 0.000000e+00 Elapsed = 3362.89 K = 2 N = 15000
|
|
|
@ -1 +0,0 @@
|
||||||
a.txt
|
|
1
2025.04.04/tests/1/a1.txt
Normal file
1
2025.04.04/tests/1/a1.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
a.txt
|
0
2025.04.04/test/test1.sh → 2025.04.04/tests/test1.sh
Executable file → Normal file
0
2025.04.04/test/test1.sh → 2025.04.04/tests/test1.sh
Executable file → Normal file
0
2025.04.04/test/test13.sh → 2025.04.04/tests/test13.sh
Executable file → Normal file
0
2025.04.04/test/test13.sh → 2025.04.04/tests/test13.sh
Executable file → Normal file
0
2025.04.04/test/test13_matr.sh → 2025.04.04/tests/test13_matr.sh
Executable file → Normal file
0
2025.04.04/test/test13_matr.sh → 2025.04.04/tests/test13_matr.sh
Executable file → Normal file
0
2025.04.04/test/test13_matr_mpi.sh → 2025.04.04/tests/test13_matr_mpi.sh
Executable file → Normal file
0
2025.04.04/test/test13_matr_mpi.sh → 2025.04.04/tests/test13_matr_mpi.sh
Executable file → Normal file
0
2025.04.04/test/test13_matr_thr.sh → 2025.04.04/tests/test13_matr_thr.sh
Executable file → Normal file
0
2025.04.04/test/test13_matr_thr.sh → 2025.04.04/tests/test13_matr_thr.sh
Executable file → Normal file
0
2025.04.04/test/test13_mpi.sh → 2025.04.04/tests/test13_mpi.sh
Executable file → Normal file
0
2025.04.04/test/test13_mpi.sh → 2025.04.04/tests/test13_mpi.sh
Executable file → Normal file
0
2025.04.04/test/test13_thr.sh → 2025.04.04/tests/test13_thr.sh
Executable file → Normal file
0
2025.04.04/test/test13_thr.sh → 2025.04.04/tests/test13_thr.sh
Executable file → Normal file
0
2025.04.04/test/test1_matr.sh → 2025.04.04/tests/test1_matr.sh
Executable file → Normal file
0
2025.04.04/test/test1_matr.sh → 2025.04.04/tests/test1_matr.sh
Executable file → Normal file
42
2025.04.18/01Ex/Makefile
Normal file
42
2025.04.18/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
|
||||||
|
|
||||||
|
CFLAGS = -std=gnu99 -mfpmath=sse -O3
|
||||||
|
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
EXE = exe
|
||||||
|
CLEAN = del
|
||||||
|
LFLAGS = -lssp -lm
|
||||||
|
else
|
||||||
|
EXE = out
|
||||||
|
CLEAN = rm -f
|
||||||
|
LFLAGS = -lm
|
||||||
|
endif
|
||||||
|
|
||||||
|
TARGET = a01.$(EXE)
|
||||||
|
OBJ = main.o solve.o array_io.o
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
gcc $(CFLAGS) $(WFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
$(TARGET): $(OBJ)
|
||||||
|
gcc $^ -o $@ $(LFLAGS)
|
||||||
|
|
||||||
|
# Отладочная сборка (gdb)
|
||||||
|
gdb: CFLAGS = -mfpmath=sse -std=gnu99 -g -O0
|
||||||
|
gdb: clean $(TARGET)
|
||||||
|
|
||||||
|
# Профилировочная сборка (gprof)
|
||||||
|
prof: CFLAGS = -std=gnu99 -mfpmath=sse -pg -O3
|
||||||
|
prof: LFLAGS = -lm -pg
|
||||||
|
prof: clean $(TARGET)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(CLEAN) *.o *$(EXE)
|
26
2025.04.18/01Ex/array_io.c
Normal file
26
2025.04.18/01Ex/array_io.c
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "array_io.h"
|
||||||
|
|
||||||
|
io_status read_values (double * restrict X, double * restrict Y, const int n, const char * restrict name)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
if (!(fp = fopen(name, "r")))
|
||||||
|
return ERROR_OPEN;
|
||||||
|
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
if (fscanf(fp, "%lf\t%lf", X + i, Y + i) != 2)
|
||||||
|
{ fclose(fp); return ERROR_READ; }
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_values (const double * restrict X, const double * restrict Y, const int n, const int p)
|
||||||
|
{
|
||||||
|
int np = (n > p ? p : n);
|
||||||
|
|
||||||
|
for (int i = 0; i < np; i++)
|
||||||
|
printf("f(%lf) = %lf\n", X[i], Y[i]);
|
||||||
|
}
|
||||||
|
|
9
2025.04.18/01Ex/array_io.h
Normal file
9
2025.04.18/01Ex/array_io.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef ARRAY_IO_H
|
||||||
|
#define ARRAY_IO_H
|
||||||
|
|
||||||
|
#include "io_status.h"
|
||||||
|
|
||||||
|
io_status read_values (double * restrict X, double * restrict Y, const int n, const char * restrict name);
|
||||||
|
void print_values (const double * restrict X, const double * restrict Y, const int n, const int p);
|
||||||
|
|
||||||
|
#endif
|
15
2025.04.18/01Ex/io_status.h
Normal file
15
2025.04.18/01Ex/io_status.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef IO_STATUS_H
|
||||||
|
#define IO_STATUS_H
|
||||||
|
|
||||||
|
#define ERR_MEM "Error: Not enough memory!"
|
||||||
|
#define ERR_OPEN "Error: Cannot open file"
|
||||||
|
#define ERR_READ "Error: Cannot read file"
|
||||||
|
|
||||||
|
typedef enum _io_status
|
||||||
|
{
|
||||||
|
SUCCESS,
|
||||||
|
ERROR_OPEN,
|
||||||
|
ERROR_READ
|
||||||
|
} io_status;
|
||||||
|
|
||||||
|
#endif
|
74
2025.04.18/01Ex/main.c
Normal file
74
2025.04.18/01Ex/main.c
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "array_io.h"
|
||||||
|
#include "io_status.h"
|
||||||
|
#include "solve.h"
|
||||||
|
|
||||||
|
/* ./a.out x_0 n filename */
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
double x_0, t, r = 0, *X = 0, *Y = 0;
|
||||||
|
int n, task = 1;
|
||||||
|
char *name = 0;
|
||||||
|
io_status ret;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!((argc == 4) &&
|
||||||
|
sscanf(argv[1], "%lf", &x_0) == 1 &&
|
||||||
|
sscanf(argv[2], "%d", &n) == 1 &&
|
||||||
|
((name = argv[3]) && name))
|
||||||
|
) {
|
||||||
|
fprintf(stderr, "Usage: %s x_0 n filename\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Удалить вывод в stderr
|
||||||
|
X = (double *)malloc(n * sizeof(double));
|
||||||
|
if (!X)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s\n", ERR_MEM);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Y = (double *)malloc(n * sizeof(double));
|
||||||
|
if (!Y)
|
||||||
|
{
|
||||||
|
free(X);
|
||||||
|
fprintf(stderr, "%s\n", ERR_MEM);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = read_values(X, Y, n, name);
|
||||||
|
do {
|
||||||
|
switch (ret)
|
||||||
|
{
|
||||||
|
case SUCCESS:
|
||||||
|
continue;
|
||||||
|
case ERROR_OPEN:
|
||||||
|
fprintf(stderr, "%s '%s'!\n", ERR_OPEN, name);
|
||||||
|
break;
|
||||||
|
case ERROR_READ:
|
||||||
|
fprintf(stderr, "%s '%s'!\n", ERR_READ, name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(X);
|
||||||
|
free(Y);
|
||||||
|
|
||||||
|
return 3;
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
t = clock();
|
||||||
|
r = t1_solve(x_0, n, X, Y);
|
||||||
|
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
printf("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, r, t);
|
||||||
|
|
||||||
|
free(X);
|
||||||
|
free(Y);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
43
2025.04.18/01Ex/solve.c
Normal file
43
2025.04.18/01Ex/solve.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#include "solve.h"
|
||||||
|
|
||||||
|
#include <float.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
// the Lagrange interpolation polynomial
|
||||||
|
double t1_solve (const double x_0, const int n, const double * restrict X, const double * restrict Y)
|
||||||
|
{
|
||||||
|
double value = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
{
|
||||||
|
double x_i = X[i];
|
||||||
|
double y_i = Y[i];
|
||||||
|
|
||||||
|
double numerator = y_i;
|
||||||
|
double denominator = 1;
|
||||||
|
|
||||||
|
if (fabs(x_0 - x_i) < DBL_EPSILON)
|
||||||
|
return y_i;
|
||||||
|
|
||||||
|
for (int j = 0; j < i; ++j)
|
||||||
|
{
|
||||||
|
double x_j = X[j];
|
||||||
|
numerator *= (x_0 - x_j);
|
||||||
|
denominator *= (x_i - x_j);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = i+1; j < n; ++j)
|
||||||
|
{
|
||||||
|
double x_j = X[j];
|
||||||
|
numerator *= (x_0 - x_j);
|
||||||
|
denominator *= (x_i - x_j);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fabs(denominator) < DBL_EPSILON)
|
||||||
|
return DBL_MAX;
|
||||||
|
|
||||||
|
value += numerator / denominator;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
6
2025.04.18/01Ex/solve.h
Normal file
6
2025.04.18/01Ex/solve.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef SOLVE_H
|
||||||
|
#define SOLVE_H
|
||||||
|
|
||||||
|
double t1_solve (const double x_0, const int n, const double * restrict X, const double * restrict Y);
|
||||||
|
|
||||||
|
#endif
|
8
2025.04.18/tests/linear.txt
Normal file
8
2025.04.18/tests/linear.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
1 1
|
||||||
|
2 2
|
||||||
|
3 3
|
||||||
|
4 4
|
||||||
|
5 5
|
||||||
|
6 6
|
||||||
|
7 7
|
||||||
|
8 8
|
9
2025.04.18/tests/linear_d.txt
Normal file
9
2025.04.18/tests/linear_d.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
1 1 1
|
||||||
|
2 2 1
|
||||||
|
3 3 1
|
||||||
|
4 4 1
|
||||||
|
5 5 1
|
||||||
|
6 6 1
|
||||||
|
7 7 1
|
||||||
|
8 8 1
|
||||||
|
|
16
2025.04.18/tests/log2_x.txt
Normal file
16
2025.04.18/tests/log2_x.txt
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
1 0
|
||||||
|
2 1
|
||||||
|
4 2
|
||||||
|
8 3
|
||||||
|
16 4
|
||||||
|
32 5
|
||||||
|
64 6
|
||||||
|
128 7
|
||||||
|
256 8
|
||||||
|
512 9
|
||||||
|
1024 10
|
||||||
|
2048 11
|
||||||
|
4096 12
|
||||||
|
8192 13
|
||||||
|
16384 14
|
||||||
|
32768 15
|
Loading…
Add table
Add a link
Reference in a new issue