Add dist ans Task 5 is done!

This commit is contained in:
AZEN-SGG 2025-04-17 21:56:31 +03:00
parent 4a5c5ea41e
commit 2f21a20fd1
21 changed files with 970 additions and 37 deletions

View file

@ -25,34 +25,23 @@ double t4_solve (
return DBL_MAX;
Y[i+1] = (y_j - y_i) / (x_j - x_i);
// printf ("I = %d, f(x%d, ... , x%d) = %lf\n", i, i+1, i+2, Y[i+1]);
y_j = y_i;
x_j = x_i;
}
// for (int i = 1; i < n; ++i)
// printf ("f(x%d, x%d) = %lf\n", i-1, i, Y[i]);
for (int k = 1; k < n*2-1; ++k)
{
double f_j = D[n-1];
// printf ("------- K = %d -------\n", k);
for (int l = n*2-2; l >= k; --l)
{
const int i = l >> 1;
double x_i, f_i, *f;
// printf ("--- L = %d, I = %d ---\n", l , i);
if (l & 1)
{
x_i = X[i-(k>>1)];
// printf ("f(x%d, ", i-(k>>1));
// for (int j = i-(k>>1)+1; j < i+(l&1); j++)
// printf ("x%d, ", j);
f_i = D[i];
f = Y + i + 1;
@ -60,52 +49,29 @@ double t4_solve (
{
x_j = X[i];
x_i = X[i-(k>>1)-(k&1)];
// printf ("f(x%d, ", i-(k>>1)-(k&1));
// for (int j = i-(k>>1)-(k&1)+1; j < i+(l&1); j++)
// printf ("x%d, ", j);
f_i = Y[i];
f = D + i;
}
// printf ("x%d)\n", i+(l&1));
if (fabs(x_j - x_i) < DBL_EPSILON)
return DBL_MAX;
*f = (f_j - f_i) / (x_j - x_i);
// printf ("f(x%d, x%d, ..., x%d) = %lf\n", i-k, i-k, i+1, Y[i+1]);
// printf ("f(x%d, ..., x%d, x%d) = %lf\n", i-k, i+1, i+1, D[i+1]);
f_j = f_i;
// printf ("I = %d, f(x%d, ... , x%d) = %lf\n", i, i-k+1, i+2, Y[i+1]);
}
// printf("------- Y -------\n");
// for (int i = 0; i < n; ++i)
// printf("Y[%d] = %lf\n", i, Y[i]);
// printf("------- D -------\n");
// for (int i = 0; i < n; ++i)
// printf("D[%d] = %lf\n", i, D[i]);
}
start_value = 1;
value = 0;
// printf("------- Y -------\n");
// for (int i = 0; i < n; ++i)
// printf("Y[%d] = %lf\n", i, Y[i]);
// printf("------- D -------\n");
// for (int i = 0; i < n; ++i)
// printf("D[%d] = %lf\n", i, D[i]);
for (int i = 0; i < n; ++i)
{
const double diff = (x_0 - X[i]);
value += Y[i] * start_value;
start_value *= diff;
value += D[i] * start_value;
start_value *= diff;
}

42
2025.04.18/05Ex/Makefile Normal file
View 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 = a05.$(EXE)
OBJ = main.o solve.o contin_func.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)

View file

@ -0,0 +1,38 @@
#include "contin_func.h"
#include <math.h>
#include <float.h>
double ssin (const double x, const double eps)
{
double value = 0;
double el = x;
int i = 1;
while (fabs(el) - eps >= DBL_EPSILON)
{
value += el;
el *= -(x*x / (i*i + 3*i + 2));
i+=2;
}
return value;
}
double scos (const double x, const double eps)
{
double value = 0;
double el = 1;
int i = 0;
while (fabs(el) - eps >= DBL_EPSILON)
{
value += el;
el *= - (x*x / (i*i + 3*i + 2));
i+=2;
}
return value;
}

View file

@ -0,0 +1,7 @@
#ifndef CONTIN_FUNC_H
#define CONTIN_FUNC_H
double ssin (const double x, const double eps);
double scos (const double x, const double eps);
#endif

View file

@ -0,0 +1,9 @@
#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"
#define ERR_FUNC "Error: Algorithm is not applicable!"
#endif

34
2025.04.18/05Ex/main.c Normal file
View file

@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "io_status.h"
#include "solve.h"
/* ./a.out x eps */
int main(int argc, char *argv[])
{
double x, eps, t, r1 = 0, r2 = 0;
int task = 5;
if (
!((argc == 3) &&
sscanf(argv[1], "%lf", &x) == 1 &&
((sscanf(argv[2], "%lf", &eps) == 1) && eps > 0))
) {
fprintf(stderr, "Usage: %s x eps\n", argv[0]);
return 1;
}
t = clock();
r1 = fsin(x, eps);
t = (clock() - t) / CLOCKS_PER_SEC;
r2 = fabs(r1 - sin(x));
printf("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], task, r1, r2, t);
return 0;
}

49
2025.04.18/05Ex/solve.c Normal file
View file

@ -0,0 +1,49 @@
#include "solve.h"
#include "contin_func.h"
#include <stdlib.h>
#include <math.h>
#include <float.h>
double fsin (double x, const double eps)
{
double answer;
short flag = 1;
if (-x > DBL_EPSILON)
{
x = -x;
flag = -1;
}
if (x - M_PI*2 >= DBL_EPSILON)
x = fmod(x, M_PI*2);
if (x - M_PI >= DBL_EPSILON)
{
x -= M_PI;
flag *= -1;
}
if (x - M_PI_2 >= DBL_EPSILON)
{
x -= M_PI_2;
flag *= 2;
}
if (abs(flag) == 2)
{
double cosinus, sinus;
x /= 2;
cosinus = scos(x, eps);
sinus = ssin(x, eps);
answer = ((flag > 0) - (flag < 0)) * (cosinus * cosinus - sinus * sinus);
} else
answer = flag * ssin(x, eps);
return answer;
}

6
2025.04.18/05Ex/solve.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef SOLVE_H
#define SOLVE_H
double fsin (double x, const double eps);
#endif

View file

@ -0,0 +1,15 @@
FLAGS = -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 -O3
%.out: %.o solve.o array_io.o contin_func.o
gcc $(FLAGS) $^ -o $@ -lm
%.o: %.c
gcc -c $(FLAGS) $<
all: a01.out a02.out a03.out a04.out a05.out
solve.o: solve.c solve.h
array_io.o: array_io.c array_io.h
contin_func.o: contin_func.c contin_func.h
clean:
rm -f *.o *.out

85
2025.04.18/dist/Krivoruchenko_SK/a01.c vendored Normal file
View file

@ -0,0 +1,85 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <float.h>
#include <math.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) && n > 0) &&
((name = argv[3]) && name))
) {
fprintf(stderr, "Usage: %s x_0 n filename\n", argv[0]);
return 1;
}
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;
if (fabs(r - DBL_MAX) < DBL_EPSILON)
{
fprintf(stderr, "%s\n", ERR_FUNC);
free(X);
free(Y);
return 4;
}
printf("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, r, t);
free(X);
free(Y);
return 0;
}

85
2025.04.18/dist/Krivoruchenko_SK/a02.c vendored Normal file
View file

@ -0,0 +1,85 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <float.h>
#include <math.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 = 2;
char *name = 0;
io_status ret;
if (
!((argc == 4) &&
sscanf(argv[1], "%lf", &x_0) == 1 &&
((sscanf(argv[2], "%d", &n) == 1) && n > 0) &&
((name = argv[3]) && name))
) {
fprintf(stderr, "Usage: %s x_0 n filename\n", argv[0]);
return 1;
}
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 = t2_solve(x_0, n, X, Y);
t = (clock() - t) / CLOCKS_PER_SEC;
if (fabs(r - DBL_MAX) < DBL_EPSILON)
{
fprintf(stderr, "%s\n", ERR_FUNC);
free(X);
free(Y);
return 4;
}
printf("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, r, t);
free(X);
free(Y);
return 0;
}

85
2025.04.18/dist/Krivoruchenko_SK/a03.c vendored Normal file
View file

@ -0,0 +1,85 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <float.h>
#include <math.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 = 3;
char *name = 0;
io_status ret;
if (
!((argc == 4) &&
sscanf(argv[1], "%lf", &x_0) == 1 &&
((sscanf(argv[2], "%d", &n) == 1) && n > 0) &&
((name = argv[3]) && name))
) {
fprintf(stderr, "Usage: %s x_0 n filename\n", argv[0]);
return 1;
}
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 = t3_solve(x_0, n, X, Y);
t = (clock() - t) / CLOCKS_PER_SEC;
if (fabs(r - DBL_MAX) < DBL_EPSILON)
{
fprintf(stderr, "%s\n", ERR_FUNC);
free(X);
free(Y);
return 4;
}
printf("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, r, t);
free(X);
free(Y);
return 0;
}

97
2025.04.18/dist/Krivoruchenko_SK/a04.c vendored Normal file
View file

@ -0,0 +1,97 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <float.h>
#include <math.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, *D = 0;
int n, task = 4;
char *name = 0;
io_status ret;
if (
!((argc == 4) &&
sscanf(argv[1], "%lf", &x_0) == 1 &&
((sscanf(argv[2], "%d", &n) == 1) && n > 0) &&
((name = argv[3]) && name))
) {
fprintf(stderr, "Usage: %s x_0 n filename\n", argv[0]);
return 1;
}
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;
}
D = (double *)malloc(n * sizeof(double));
if (!D)
{
free(X);
free(Y);
fprintf(stderr, "%s\n", ERR_MEM);
return 2;
}
ret = read_values_and_derivatives(X, Y, D, 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);
free(D);
return 3;
} while (0);
t = clock();
r = t4_solve(x_0, n, X, Y, D);
t = (clock() - t) / CLOCKS_PER_SEC;
if (fabs(r - DBL_MAX) < DBL_EPSILON)
{
fprintf(stderr, "%s\n", ERR_FUNC);
free(X);
free(Y);
free(D);
return 4;
}
printf("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, r, t);
free(X);
free(Y);
free(D);
return 0;
}

34
2025.04.18/dist/Krivoruchenko_SK/a05.c vendored Normal file
View file

@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "io_status.h"
#include "solve.h"
/* ./a.out x eps */
int main(int argc, char *argv[])
{
double x, eps, t, r1 = 0, r2 = 0;
int task = 5;
if (
!((argc == 3) &&
sscanf(argv[1], "%lf", &x) == 1 &&
((sscanf(argv[2], "%lf", &eps) == 1) && eps > 0))
) {
fprintf(stderr, "Usage: %s x eps\n", argv[0]);
return 1;
}
t = clock();
r1 = fsin(x, eps);
t = (clock() - t) / CLOCKS_PER_SEC;
r2 = fabs(r1 - sin(x));
printf("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], task, r1, r2, t);
return 0;
}

View file

@ -0,0 +1,59 @@
#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;
}
io_status read_values_and_derivatives (
double * restrict X,
double * restrict Y,
double * restrict D,
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\t%lf", X + i, Y + i, D + i) != 3)
{ 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]);
}
void print_values_and_derivatives (
const double * restrict X,
const double * restrict Y,
const double * restrict D,
const int n, const int p
)
{
int np = (n > p ? p : n);
for (int i = 0; i < np; i++)
printf("f(%lf) = %lf, f`(%lf) = %lf\n", X[i], Y[i], X[i], D[i]);
}

View file

@ -0,0 +1,22 @@
#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);
io_status read_values_and_derivatives (
double * restrict X,
double * restrict Y,
double * restrict D,
const int n,
const char * restrict name
);
void print_values_and_derivatives (
const double * restrict X,
const double * restrict Y,
const double * restrict D,
const int n, const int p
);
#endif

View file

@ -0,0 +1,38 @@
#include "contin_func.h"
#include <math.h>
#include <float.h>
double ssin (const double x, const double eps)
{
double value = 0;
double el = x;
int i = 1;
while (fabs(el) - eps >= DBL_EPSILON)
{
value += el;
el *= -(x*x / (i*i + 3*i + 2));
i+=2;
}
return value;
}
double scos (const double x, const double eps)
{
double value = 0;
double el = 1;
int i = 0;
while (fabs(el) - eps >= DBL_EPSILON)
{
value += el;
el *= - (x*x / (i*i + 3*i + 2));
i+=2;
}
return value;
}

View file

@ -0,0 +1,7 @@
#ifndef CONTIN_FUNC_H
#define CONTIN_FUNC_H
double ssin (const double x, const double eps);
double scos (const double x, const double eps);
#endif

View file

@ -0,0 +1,16 @@
#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"
#define ERR_FUNC "Error: Algorithm is not applicable!"
typedef enum _io_status
{
SUCCESS,
ERROR_OPEN,
ERROR_READ
} io_status;
#endif

224
2025.04.18/dist/Krivoruchenko_SK/solve.c vendored Normal file
View file

@ -0,0 +1,224 @@
#include "solve.h"
#include "contin_func.h"
#include <stdlib.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;
}
// the Newton interpolation polynomial
double t2_solve (const double x_0, const int n, const double * restrict X, double * restrict Y)
{
double value, start_value;
for (int k = 0; k < n-1; ++k)
{
double last_x;
double last_y = Y[n-1];
for (int i = n-2; i >= k; --i)
{
const double x_i = X[i-k];
const double y_i = Y[i];
last_x = X[i+1];
if (fabs(last_x - x_i) < DBL_EPSILON)
return DBL_MAX;
Y[i+1] = (last_y - y_i) / (last_x - x_i);
last_y = y_i;
}
}
start_value = 1;
value = 0;
for (int i = 0; i < n; ++i)
{
value += Y[i] * start_value;
start_value *= (x_0 - X[i]);
}
return value;
}
// Interpolation polynomial according to Aitken's scheme
double t3_solve (const double x_0, const int n, const double * restrict X, double * restrict Y)
{
for (int k = 0; k < n-1; ++k)
{
double x_j;
double y_j = Y[n-1];
for (int i = n-2; i >= k; --i)
{
const double x_i = X[i-k];
const double y_i = Y[i];
x_j = X[i+1];
if (fabs(x_j - x_i) < DBL_EPSILON)
return DBL_MAX;
Y[i+1] = ((x_0-x_i) * y_j - (x_0-x_j) * y_i) / (x_j - x_i);
y_j = y_i;
}
}
return Y[n-1];
}
// Newton's interpolation polynomial with derivative
double t4_solve (
const double x_0, const int n,
const double * restrict X,
double * restrict Y,
double * restrict D
)
{
double value, start_value;
double x_j = X[n-1];
double y_j = Y[n-1];
for (int i = n-2; i >= 0; --i)
{
const double x_i = X[i];
const double y_i = Y[i];
if (fabs(x_j - x_i) < DBL_EPSILON)
return DBL_MAX;
Y[i+1] = (y_j - y_i) / (x_j - x_i);
y_j = y_i;
x_j = x_i;
}
for (int k = 1; k < n*2-1; ++k)
{
double f_j = D[n-1];
for (int l = n*2-2; l >= k; --l)
{
const int i = l >> 1;
double x_i, f_i, *f;
if (l & 1)
{
x_i = X[i-(k>>1)];
f_i = D[i];
f = Y + i + 1;
} else
{
x_j = X[i];
x_i = X[i-(k>>1)-(k&1)];
f_i = Y[i];
f = D + i;
}
if (fabs(x_j - x_i) < DBL_EPSILON)
return DBL_MAX;
*f = (f_j - f_i) / (x_j - x_i);
f_j = f_i;
}
}
start_value = 1;
value = 0;
for (int i = 0; i < n; ++i)
{
const double diff = (x_0 - X[i]);
value += Y[i] * start_value;
start_value *= diff;
value += D[i] * start_value;
start_value *= diff;
}
return value;
}
double fsin (double x, const double eps)
{
double answer;
short flag = 1;
if (-x > DBL_EPSILON)
{
x = -x;
flag = -1;
}
if (x - M_PI*2 >= DBL_EPSILON)
x = fmod(x, M_PI*2);
if (x - M_PI >= DBL_EPSILON)
{
x -= M_PI;
flag *= -1;
}
if (x - M_PI_2 >= DBL_EPSILON)
{
x -= M_PI_2;
flag *= 2;
}
if (abs(flag) == 2)
{
double cosinus, sinus;
x /= 2;
cosinus = scos(x, eps);
sinus = ssin(x, eps);
answer = ((flag > 0) - (flag < 0)) * (cosinus * cosinus - sinus * sinus);
} else
answer = flag * ssin(x, eps);
return answer;
}

View file

@ -0,0 +1,15 @@
#ifndef SOLVE_H
#define SOLVE_H
double t1_solve (const double x_0, const int n, const double * restrict X, const double * restrict Y);
double t2_solve (const double x_0, const int n, const double * restrict X, double * restrict Y);
double t3_solve (const double x_0, const int n, const double * restrict X, double * restrict Y);
double t4_solve (
const double x_0, const int n,
const double * restrict X,
double * restrict Y,
double * restrict D
);
double fsin (double x, const double eps);
#endif