Task 8 is done
This commit is contained in:
parent
2efd819d0f
commit
98a608ce96
22 changed files with 1270 additions and 0 deletions
42
2025.04.18/08Ex/Makefile
Normal file
42
2025.04.18/08Ex/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 = a08.$(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)
|
42
2025.04.18/08Ex/contin_func.c
Normal file
42
2025.04.18/08Ex/contin_func.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "contin_func.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
double fln (const double x, const double eps)
|
||||
{
|
||||
const double z = (x - 1) / (x + 1);
|
||||
double value = 0;
|
||||
double monom = z, el = z;
|
||||
int i = 1;
|
||||
|
||||
while (el - eps > DBL_EPSILON)
|
||||
{
|
||||
value += el;
|
||||
|
||||
i+=2;
|
||||
monom *= z*z;
|
||||
el = monom / i;
|
||||
}
|
||||
|
||||
return 2 * value;
|
||||
}
|
||||
|
||||
double sln (const double x, const double eps)
|
||||
{
|
||||
const double z = x - 1;
|
||||
double value = 0;
|
||||
double monom = z, el = z;
|
||||
int i = 1;
|
||||
|
||||
while (fabs(el) - eps > DBL_EPSILON)
|
||||
{
|
||||
value += el;
|
||||
|
||||
i++;
|
||||
monom *= -z;
|
||||
el = monom / i;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
7
2025.04.18/08Ex/contin_func.h
Normal file
7
2025.04.18/08Ex/contin_func.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef CONTIN_FUNC_H
|
||||
#define CONTIN_FUNC_H
|
||||
|
||||
double fln (const double x, const double eps);
|
||||
double sln (const double x, const double eps);
|
||||
|
||||
#endif
|
9
2025.04.18/08Ex/io_status.h
Normal file
9
2025.04.18/08Ex/io_status.h
Normal 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/08Ex/main.c
Normal file
34
2025.04.18/08Ex/main.c
Normal 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 = 8;
|
||||
|
||||
if (
|
||||
!((argc == 3) &&
|
||||
((sscanf(argv[1], "%le", &x) == 1) && x > 0) &&
|
||||
((sscanf(argv[2], "%le", &eps) == 1) && eps > 0))
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s x eps\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
t = clock();
|
||||
r1 = dln(x, eps);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
r2 = fabs(r1 - log(x));
|
||||
|
||||
printf("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], task, r1, r2, t);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
30
2025.04.18/08Ex/solve.c
Normal file
30
2025.04.18/08Ex/solve.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include "solve.h"
|
||||
#include "contin_func.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
double dln (double x, const double eps)
|
||||
{
|
||||
double value = 0;
|
||||
int b = 0;
|
||||
|
||||
while (x - 2 > DBL_EPSILON)
|
||||
{
|
||||
x *= 0.5;
|
||||
b++;
|
||||
}
|
||||
|
||||
while (x - 1 <= DBL_EPSILON)
|
||||
{
|
||||
x *= 2;
|
||||
b--;
|
||||
}
|
||||
|
||||
value = fln(x, eps);
|
||||
|
||||
value += b * M_LN2;
|
||||
return value;
|
||||
}
|
6
2025.04.18/08Ex/solve.h
Normal file
6
2025.04.18/08Ex/solve.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
double dln (double x, const double eps);
|
||||
|
||||
#endif
|
21
2025.04.18/dist/Ryabov_AD/Makefile
vendored
Normal file
21
2025.04.18/dist/Ryabov_AD/Makefile
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
all: a01.out a02.out a03.out a04.out a05.out a06.out a07.out a08.out
|
||||
|
||||
CFLAGS = -O3 -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 -lm
|
||||
|
||||
a%.out: task%.o solve.o massiv_io.o
|
||||
gcc $(CFLAGS) $^ -o $@ -lm
|
||||
|
||||
task%.o: task%.c io_status.h massiv_io.h solve.h
|
||||
gcc -c $(CFLAGS) $<
|
||||
|
||||
massiv_io.o: massiv_io.c massiv_io.h
|
||||
gcc -c $(CFLAGS) massiv_io.c
|
||||
|
||||
solve.o: solve.c solve.h
|
||||
gcc -c $(CFLAGS) solve.c
|
||||
|
||||
clean:
|
||||
rm *.o
|
6
2025.04.18/dist/Ryabov_AD/io_status.h
vendored
Normal file
6
2025.04.18/dist/Ryabov_AD/io_status.h
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
typedef enum io_status_ {
|
||||
SUCCESS, /* все хорошо */
|
||||
ERROR_OPEN, /* ошибка открытия файла */
|
||||
ERROR_READ, /* ошибка чтения файла */
|
||||
ERROR_MEM, /* ошибка выделения памяти */
|
||||
} io_status;
|
71
2025.04.18/dist/Ryabov_AD/massiv_io.c
vendored
Normal file
71
2025.04.18/dist/Ryabov_AD/massiv_io.c
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "massiv_io.h"
|
||||
|
||||
int sravn_el(double x1, double x2){
|
||||
double eps = 1e-16;
|
||||
return fabs(x1 - x2) <= eps * fmax(fabs(x1), fabs(x2));
|
||||
}
|
||||
|
||||
io_status read_file(double* x, double* y, int n, char* file_name){
|
||||
int i;
|
||||
FILE *fp;
|
||||
if (!(fp = fopen(file_name, "r"))){
|
||||
return ERROR_OPEN;
|
||||
}
|
||||
for (i = 0; i < n; i++){
|
||||
if (fscanf(fp, "%lf", x + i) != 1){
|
||||
fclose(fp);
|
||||
return ERROR_READ;
|
||||
}
|
||||
if (fscanf(fp, "%lf", y + i) != 1){
|
||||
fclose(fp);
|
||||
return ERROR_READ;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
io_status read_file_4(double* x, double* y, double*d, int n, char* file_name){
|
||||
int i, index;
|
||||
FILE *fp;
|
||||
if (!(fp = fopen(file_name, "r"))){
|
||||
return ERROR_OPEN;
|
||||
}
|
||||
index = 0;
|
||||
for (i = 0; i < n; i++){
|
||||
if (fscanf(fp, "%lf", x + i) != 1){
|
||||
fclose(fp);
|
||||
return ERROR_READ;
|
||||
}
|
||||
if (index < n){
|
||||
if (fscanf(fp, "%lf", y + index) != 1){
|
||||
fclose(fp);
|
||||
return ERROR_READ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (fscanf(fp, "%lf", d + (index % n)) != 1){
|
||||
fclose(fp);
|
||||
return ERROR_READ;
|
||||
}
|
||||
}
|
||||
index++;
|
||||
if (index < n){
|
||||
if (fscanf(fp, "%lf", y + index) != 1){
|
||||
fclose(fp);
|
||||
return ERROR_READ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (fscanf(fp, "%lf", d + (index % n)) != 1){
|
||||
fclose(fp);
|
||||
return ERROR_READ;
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
fclose(fp);
|
||||
return SUCCESS;
|
||||
}
|
5
2025.04.18/dist/Ryabov_AD/massiv_io.h
vendored
Normal file
5
2025.04.18/dist/Ryabov_AD/massiv_io.h
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include "io_status.h"
|
||||
|
||||
io_status read_file(double* x, double* y, int n, char* name_a);
|
||||
io_status read_file_4(double* x, double* y, double* d, int n, char* file_name);
|
||||
int sravn_el(double x1, double x2);
|
404
2025.04.18/dist/Ryabov_AD/solve.c
vendored
Normal file
404
2025.04.18/dist/Ryabov_AD/solve.c
vendored
Normal file
|
@ -0,0 +1,404 @@
|
|||
#include <math.h>
|
||||
#include "solve.h"
|
||||
#include "massiv_io.h"
|
||||
|
||||
int task01(double x0, int n, double* x, double* y, double*znach){
|
||||
int i, j;
|
||||
double xi, xj, output = 0;
|
||||
double chisl = 0, znam = 1;
|
||||
for (i = 0; i < n; i++){
|
||||
xi = x[i];
|
||||
chisl = 1;
|
||||
znam = 1;
|
||||
for (j = 0; j < i; j++){
|
||||
xj = x[j];
|
||||
chisl = chisl * (x0 - xj);
|
||||
znam = znam * (xi - xj);
|
||||
//printf("%d %d: x[%d] = %e xi: %e xj: %e\n", i, j, i, x[i], xi, xj);
|
||||
//printf("%e\n", xj / (xj - xi));
|
||||
}
|
||||
for (j = i + 1; j < n; j++){
|
||||
xj = x[j];
|
||||
chisl = chisl * (x0 - xj);
|
||||
znam = znam * (xi - xj);
|
||||
//printf("%d %d: x[%d] = %e xi: %e xj: %e\n", i, j, i, x[i], xi, xj);
|
||||
//printf("%e\n", xj / (xj - xi));
|
||||
}
|
||||
if (sravn_el(znam, 0)){ // произойдёт деление на ноль, отменяем
|
||||
return 1;
|
||||
}
|
||||
output += (y[i] * chisl) / znam;
|
||||
}
|
||||
*znach = output;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int task02(double x0, int n, double* x, double* y, double* znach){
|
||||
int i, m;
|
||||
double p;
|
||||
double pred_el, razn, tek_el;
|
||||
(void)x0;
|
||||
/*
|
||||
printf("do x:\n");
|
||||
for (i = 0; i < n; i++){
|
||||
printf("%lf\n", x[i]);
|
||||
}
|
||||
printf("do y:\n");
|
||||
for (i = 0; i < n; i++){
|
||||
printf("%lf\n", y[i]);
|
||||
}
|
||||
*/
|
||||
for (m = 1; m < n; m++){
|
||||
pred_el = y[n - 1];
|
||||
for (i = n - 1; i >= m; i--){
|
||||
tek_el = y[i - 1];
|
||||
razn = x[i] - x[i - m];
|
||||
if (sravn_el(razn, 0)){
|
||||
return 1;
|
||||
}
|
||||
y[i] = (pred_el - tek_el) / razn;
|
||||
pred_el = tek_el;
|
||||
}
|
||||
/*
|
||||
printf("posle %d:\n", m);
|
||||
for (i = 0; i < n; i++){
|
||||
printf("%lf\n", y[i]);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
p = 0;
|
||||
for (i = n - 1; i >= 1; i--){
|
||||
p = (p + y[i]) * (x0 - x[i - 1]);
|
||||
}
|
||||
p = p + y[0];
|
||||
*znach = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int task03(double x0, int n, double* x, double* y, double*znach){
|
||||
int i, m;
|
||||
double sled_el, razn, tek_el;
|
||||
(void)x0;
|
||||
|
||||
/*
|
||||
printf("do x:\n");
|
||||
for (i = 0; i < n; i++){
|
||||
printf("%lf\n", x[i]);
|
||||
}
|
||||
printf("do y:\n");
|
||||
for (i = 0; i < n; i++){
|
||||
printf("%lf\n", y[i]);
|
||||
}
|
||||
*/
|
||||
|
||||
for (m = 1; m < n; m++){
|
||||
tek_el = y[0];
|
||||
for (i = 0; i < n - m; i++){
|
||||
sled_el = y[i + 1];
|
||||
razn = x[i + m] - x[i];
|
||||
/*
|
||||
printf("sled = %lf\n", sled_el);
|
||||
printf("tek = %lf\n", tek_el);
|
||||
printf("%lf\n", razn);
|
||||
*/
|
||||
if (sravn_el(razn, 0)){
|
||||
return 1;
|
||||
}
|
||||
y[i] = (sled_el * (x0 - x[i]) - tek_el * (x0 - x[i + m])) / razn;
|
||||
tek_el = sled_el;
|
||||
}
|
||||
/*
|
||||
//printf("posle %d:\n", m);
|
||||
for (i = 0; i < n; i++){
|
||||
//printf("%lf\n", y[i]);
|
||||
}
|
||||
//printf("-----\n");
|
||||
*/
|
||||
}
|
||||
*znach = y[0];
|
||||
return 0;
|
||||
}
|
||||
|
||||
double task04(double x0, int n, double* x, double* y, double* d, double*znach){
|
||||
int i, m;
|
||||
double p;
|
||||
double pred_el, razn, tek_el;
|
||||
int double_n = 2 * n;
|
||||
(void)x0;
|
||||
(void)n;
|
||||
(void)x;
|
||||
(void)y;
|
||||
(void)d;
|
||||
(void)*znach;
|
||||
(void)m;
|
||||
/*
|
||||
printf("y:\n");
|
||||
for (i = 0; i<n;i++){
|
||||
printf("%lf\n", y[i]);
|
||||
}
|
||||
printf("d:\n");
|
||||
for (i = 0; i<n;i++){
|
||||
printf("%lf\n", d[i]);
|
||||
}
|
||||
*/
|
||||
pred_el = y[n - 1];
|
||||
m = 1;
|
||||
for (i = n - 1; i > 0; i--){
|
||||
if (2 * i - 2 >= n){
|
||||
d[(2 * i) % n] = (d[(2 * i) % n] - d[(2 * i - 2) % n]) / (x[i % n] - x[(i - 1) % n]);
|
||||
}
|
||||
else if (2 * i >= n && 2 * i - 2 < n){
|
||||
d[(2 * i) % n] = (d[(2 * i) % n] - y[2 * i - 2]) / (x[i % n] - x[(i - 1) % n]);
|
||||
}
|
||||
else{
|
||||
y[2 * i] = (y[2 * i] - y[2 * i - 2]) / (x[i] - x[i - 1]);
|
||||
}
|
||||
}
|
||||
for (m = 2; m < double_n; m++){
|
||||
// printf("----\n");
|
||||
for (i = double_n - 1; i >= m; i--){
|
||||
if (i - 1 >= n){
|
||||
pred_el = d[i % n];
|
||||
tek_el = d[(i - 1) % n];
|
||||
razn = x[(i - m) / 2] - x[i / 2];
|
||||
if (sravn_el(razn, 0)) return 1;
|
||||
d[i % n] = (pred_el - tek_el) / razn;
|
||||
}
|
||||
else if (i == n){
|
||||
pred_el = d[i % n];
|
||||
tek_el = y[i - 1];
|
||||
razn = x[(i - m) / 2] - x[i / 2];
|
||||
if (sravn_el(razn, 0)) return 1;
|
||||
d[i % n] = (pred_el - tek_el) / razn;
|
||||
}
|
||||
else{
|
||||
pred_el = y[i];
|
||||
tek_el = y[i - 1];
|
||||
razn = x[(i - m) / 2] - x[i / 2];
|
||||
if (sravn_el(razn, 0)) return 1;
|
||||
y[i] = (pred_el - tek_el) / razn;
|
||||
}
|
||||
}
|
||||
p = 0;
|
||||
for (i = double_n - 1; i >= 1; i--){
|
||||
if (i >= n){
|
||||
p = (p + d[i % n]) * (x0 - x[(i - 1) / 2]);
|
||||
}
|
||||
else{
|
||||
p = (p + y[i]) * (x0 - x[(i - 1) / 2]);
|
||||
}
|
||||
}
|
||||
p = p + y[0];
|
||||
*znach = p;
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
printf("y:\n");
|
||||
for (i = 0; i < n; i++){
|
||||
printf("%lf\n", y[i]);
|
||||
}
|
||||
*/
|
||||
// Пересчитываем первичную фазу
|
||||
return 0;
|
||||
}
|
||||
|
||||
double task06(double x0, double eps){ // ПРОТЕСТИРОВАТЬ
|
||||
int is_minus = 0;
|
||||
double output;
|
||||
double coss, sinn;
|
||||
(void)eps;
|
||||
//printf("ist cos: %lf\n", cos(x0));
|
||||
x0 = fabs(x0);
|
||||
if (x0 >= 2 * M_PI){
|
||||
x0 = fmod(x0, 2 * M_PI);
|
||||
}
|
||||
//printf("ist cos: %lf\n", cos(x0));
|
||||
if (x0 >= M_PI){
|
||||
is_minus = 1;
|
||||
x0 = fmod(x0, M_PI);
|
||||
}
|
||||
//printf("ist cos: %lf\n", cos(x0));
|
||||
//printf("x0:%lf\n", x0);
|
||||
if (x0 > 1){
|
||||
/*
|
||||
printf("ist cos / 2: %lf\n", cos(x0 / 2));
|
||||
printf("x0 / 2:%lf\n", x0 / 2);
|
||||
printf("cos: %lf\n", calculate_cos(x0 / 2, eps) * calculate_cos(x0 / 2, eps));
|
||||
printf("sin: %lf\n", calculate_sin(x0 / 2, eps) * calculate_sin(x0 / 2, eps));
|
||||
*/
|
||||
coss = calculate_cos(x0 / 2, eps);
|
||||
sinn = calculate_sin(x0 / 2, eps);
|
||||
output = coss * coss - sinn * sinn;
|
||||
}
|
||||
else{
|
||||
output = calculate_cos(x0, eps);
|
||||
}
|
||||
if (is_minus) output = output * (-1);
|
||||
return output;
|
||||
}
|
||||
|
||||
double task05(double x0, double eps){ // ПРОТЕСТИРОВАТЬ
|
||||
int is_minus = 0;
|
||||
double output;
|
||||
//printf("ist sin: %lf\n", sin(x0));
|
||||
if (x0 < 0){
|
||||
is_minus = 1;
|
||||
x0 = fabs(x0);
|
||||
}
|
||||
if (x0 >= 2 * M_PI){
|
||||
x0 = fmod(x0, 2 * M_PI);
|
||||
}
|
||||
//printf("ist sin: %lf\n", sin(x0));
|
||||
if (x0 >= M_PI){
|
||||
is_minus = (is_minus + 1) % 2;
|
||||
x0 = fmod(x0, M_PI);
|
||||
}
|
||||
//printf("ist sin: %lf\n", sin(x0));
|
||||
//printf("x0:%lf\n", x0);
|
||||
if (x0 > 1){
|
||||
/*
|
||||
printf("ist sin / 2: %lf\n", sin(x0 / 2));
|
||||
printf("x0 / 2:%lf\n", x0 / 2);
|
||||
printf("cos: %lf\n", calculate_cos(x0 / 2, eps));
|
||||
printf("sin: %lf\n", calculate_sin(x0 / 2, eps));
|
||||
*/
|
||||
output = 2 * calculate_cos(x0 / 2, eps) * calculate_sin(x0 / 2, eps);
|
||||
}
|
||||
else{
|
||||
output = calculate_sin(x0, eps);
|
||||
}
|
||||
if (is_minus) output = output * (-1);
|
||||
return output;
|
||||
}
|
||||
|
||||
double calculate_cos(double x0, double eps){ // ПРОТЕСТИРОВАТЬ
|
||||
int i, chet;
|
||||
double output = 0;
|
||||
double slag = 1;
|
||||
for (i = 0, chet = 0;;i+=2, chet++){
|
||||
// printf("slag: %lf\n", slag);
|
||||
if (chet % 2 == 0){
|
||||
output += slag;
|
||||
}
|
||||
else {
|
||||
output -= slag;
|
||||
}
|
||||
// printf("output: %lf\n", output);
|
||||
slag = slag * x0 * x0;
|
||||
slag = slag / ((i + 1) * (i + 2));
|
||||
if (fabs(slag) < eps) break;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
double calculate_sin(double x0, double eps){ // ПРОТЕСТИРОВАТЬ
|
||||
int i, chet;
|
||||
double output = 0;
|
||||
double slag = x0;
|
||||
for (i = 1, chet = 0;;i+=2, chet++){
|
||||
//printf("slag: %lf\n", slag);
|
||||
if (chet % 2 == 0){
|
||||
output += slag;
|
||||
}
|
||||
else {
|
||||
output -= slag;
|
||||
}
|
||||
//printf("output: %lf\n", output);
|
||||
slag = slag * x0 * x0;
|
||||
slag = slag / ((i + 1) * (i + 2));
|
||||
if (fabs(slag) < eps) break;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
double task07(double x0, double eps){ // ПРОТЕСТИРОВАТЬ
|
||||
double chel_ch;
|
||||
double dr_ch;
|
||||
double output = 1;
|
||||
int i;
|
||||
if (x0 >= 0){
|
||||
chel_ch = floor(x0);
|
||||
dr_ch = x0 - chel_ch;
|
||||
for (i = 1; i <= chel_ch; i++){
|
||||
output *= M_E;
|
||||
}
|
||||
}
|
||||
else{
|
||||
chel_ch = ceil(x0);
|
||||
dr_ch = x0 - chel_ch;
|
||||
for (i = -1; i >= chel_ch; i--){
|
||||
output /=M_E;
|
||||
}
|
||||
}
|
||||
//printf("%lf %lf\n", chel_ch, dr_ch);
|
||||
dr_ch = calculate_exp(dr_ch, eps);
|
||||
return output * dr_ch;
|
||||
}
|
||||
|
||||
double calculate_exp(double x0, double eps){
|
||||
int i;
|
||||
double output = 0;
|
||||
double slag = 1;
|
||||
for (i = 1; ;i++){
|
||||
//printf("slag: %lf\n", slag);
|
||||
//printf("output: %lf\n", output);
|
||||
output += slag;
|
||||
slag = slag * x0;
|
||||
slag = slag / i;
|
||||
if (fabs(slag) < eps) break;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
double task08(double x0, double eps){ // ПРОТЕСТИРОВАТЬ ЭТО И ФУНКЦИИ НИЖЕ
|
||||
int b = 0;
|
||||
double ch;
|
||||
double a;
|
||||
double output;
|
||||
if (x0 >= 0.5){
|
||||
ch = st_2(x0, &b);
|
||||
a = x0 / ch;
|
||||
output = calculate_log(a, eps) + b * M_LN2;
|
||||
//printf("a: %lf b: %d\n", a, b);
|
||||
}
|
||||
else {
|
||||
a = x0;
|
||||
output = calculate_log(a, eps);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
double st_2(double x, int *c){ // ПРОТЕСТИРОВАТЬ
|
||||
int d_x;
|
||||
double output = 1.;
|
||||
if (x >= 1.){
|
||||
d_x = x;
|
||||
output = 1;
|
||||
while (output <= d_x){
|
||||
output *= 2;
|
||||
*c += 1;
|
||||
}
|
||||
*c += 1;
|
||||
return 2 *output;
|
||||
}
|
||||
else { // предполагаем, что сюда меньше 0,5 не попадает
|
||||
*c = 1;
|
||||
output = 2;
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double calculate_log(double z, double eps){ // ПРОТЕСТИРОВАТЬ
|
||||
double x = (z - 1) / (z + 1);
|
||||
int i;
|
||||
double output = 0;
|
||||
double slag = x;
|
||||
for (i = 1; ;i+= 2){
|
||||
output += slag / i;
|
||||
slag = slag * x * x;
|
||||
if (fabs(slag) < eps) break;
|
||||
}
|
||||
return 2 * output;
|
||||
}
|
16
2025.04.18/dist/Ryabov_AD/solve.h
vendored
Normal file
16
2025.04.18/dist/Ryabov_AD/solve.h
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
int task01(double x0, int n, double* x, double* y, double* res);
|
||||
int task02(double x0, int n, double* x, double* y, double* res);
|
||||
int task03(double x0, int n, double* x, double* y, double* res);
|
||||
double task04(double x0, int n, double* x, double* y, double* d, double* res);
|
||||
|
||||
double task05(double x0, double eps);
|
||||
double task06(double x0, double eps);
|
||||
double task07(double x0, double eps);
|
||||
double task08(double x0, double exp);
|
||||
|
||||
double calculate_cos(double x0, double eps);
|
||||
double calculate_sin(double x0, double eps);
|
||||
double calculate_exp(double x0, double eps);
|
||||
double calculate_log(double z, double eps);
|
||||
|
||||
double st_2(double x, int*c);
|
69
2025.04.18/dist/Ryabov_AD/task01.c
vendored
Normal file
69
2025.04.18/dist/Ryabov_AD/task01.c
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include "massiv_io.h"
|
||||
#include "solve.h"
|
||||
|
||||
|
||||
int main(int argc, char*argv[]){
|
||||
double *x, *y;
|
||||
int n;
|
||||
double t, x0;
|
||||
double res;
|
||||
int ret;
|
||||
char *file_name;
|
||||
if (!(argc == 4 && sscanf(argv[1], "%lf", &x0) == 1 && sscanf(argv[2], "%d", &n) == 1)){
|
||||
printf("Usage %s\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (n <= 0){
|
||||
printf("With zero points impossible to plot graph\n");
|
||||
return 1;
|
||||
}
|
||||
file_name = argv[3];
|
||||
// Массив x
|
||||
x = (double *)malloc(n * sizeof(double));
|
||||
if (!x){
|
||||
printf("No pamyat\n");
|
||||
return 2;
|
||||
}
|
||||
// Массив y
|
||||
y = (double *)malloc(n * sizeof(double));
|
||||
if (!y){
|
||||
printf("No pamyat\n");
|
||||
free(x);
|
||||
return 2;
|
||||
}
|
||||
ret = read_file(x, y, n, file_name);
|
||||
switch (ret){
|
||||
case SUCCESS:
|
||||
break;
|
||||
case ERROR_OPEN:
|
||||
printf("Can not open %s\n", file_name);
|
||||
break;
|
||||
case ERROR_READ:
|
||||
printf("Can not read %s\n", file_name);
|
||||
break;
|
||||
case ERROR_MEM:
|
||||
printf("Not enough memory\n");
|
||||
break;
|
||||
}
|
||||
if (ret != SUCCESS){
|
||||
free(x);
|
||||
free(y);
|
||||
return 3;
|
||||
}
|
||||
t = clock();
|
||||
ret = task01(x0, n, x, y, &res);
|
||||
if (ret == 1){ // ПРОВЕРЯЕМ ОШИБКУ в ret
|
||||
printf("Division by zero occurs. Most likely, were two identical points in file.");
|
||||
free(x);
|
||||
free(y);
|
||||
return 4;
|
||||
}
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], 1, res, t);
|
||||
free(x);
|
||||
free(y);
|
||||
return 0;
|
||||
}
|
69
2025.04.18/dist/Ryabov_AD/task02.c
vendored
Normal file
69
2025.04.18/dist/Ryabov_AD/task02.c
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include "massiv_io.h"
|
||||
#include "solve.h"
|
||||
|
||||
|
||||
int main(int argc, char*argv[]){
|
||||
double *x, *y;
|
||||
int n;
|
||||
double t, x0;
|
||||
double res;
|
||||
int ret;
|
||||
char *file_name;
|
||||
if (!(argc == 4 && sscanf(argv[1], "%lf", &x0) == 1 && sscanf(argv[2], "%d", &n) == 1)){
|
||||
printf("Usage %s\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (n <= 0){
|
||||
printf("With zero points impossible to plot graph\n");
|
||||
return 1;
|
||||
}
|
||||
file_name = argv[3];
|
||||
// Массив x
|
||||
x = (double *)malloc(n * sizeof(double));
|
||||
if (!x){
|
||||
printf("No pamyat\n");
|
||||
return 2;
|
||||
}
|
||||
// Массив y
|
||||
y = (double *)malloc(n * sizeof(double));
|
||||
if (!y){
|
||||
printf("No pamyat\n");
|
||||
free(x);
|
||||
return 2;
|
||||
}
|
||||
ret = read_file(x, y, n, file_name);
|
||||
switch (ret){
|
||||
case SUCCESS:
|
||||
break;
|
||||
case ERROR_OPEN:
|
||||
printf("Can not open %s\n", file_name);
|
||||
break;
|
||||
case ERROR_READ:
|
||||
printf("Can not read %s\n", file_name);
|
||||
break;
|
||||
case ERROR_MEM:
|
||||
printf("Not enough memory\n");
|
||||
break;
|
||||
}
|
||||
if (ret != SUCCESS){
|
||||
free(x);
|
||||
free(y);
|
||||
return 3;
|
||||
}
|
||||
t = clock();
|
||||
ret = task02(x0, n, x, y, &res);
|
||||
if (ret == 1){ // ПРОВЕРЯЕМ ОШИБКУ в ret
|
||||
printf("Division by zero occurs. Most likely, were two identical points in file.");
|
||||
free(x);
|
||||
free(y);
|
||||
return 4;
|
||||
}
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], 2, res, t);
|
||||
free(x);
|
||||
free(y);
|
||||
return 0;
|
||||
}
|
69
2025.04.18/dist/Ryabov_AD/task03.c
vendored
Normal file
69
2025.04.18/dist/Ryabov_AD/task03.c
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include "massiv_io.h"
|
||||
#include "solve.h"
|
||||
|
||||
|
||||
int main(int argc, char*argv[]){
|
||||
double *x, *y;
|
||||
int n;
|
||||
double t, x0;
|
||||
double res;
|
||||
int ret;
|
||||
char *file_name;
|
||||
if (!(argc == 4 && sscanf(argv[1], "%lf", &x0) == 1 && sscanf(argv[2], "%d", &n) == 1)){
|
||||
printf("Usage %s\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (n <= 0){
|
||||
printf("With zero points impossible to plot graph\n");
|
||||
return 1;
|
||||
}
|
||||
file_name = argv[3];
|
||||
// Массив x
|
||||
x = (double *)malloc(n * sizeof(double));
|
||||
if (!x){
|
||||
printf("No pamyat\n");
|
||||
return 2;
|
||||
}
|
||||
// Массив y
|
||||
y = (double *)malloc(n * sizeof(double));
|
||||
if (!y){
|
||||
printf("No pamyat\n");
|
||||
free(x);
|
||||
return 2;
|
||||
}
|
||||
ret = read_file(x, y, n, file_name);
|
||||
switch (ret){
|
||||
case SUCCESS:
|
||||
break;
|
||||
case ERROR_OPEN:
|
||||
printf("Can not open %s\n", file_name);
|
||||
break;
|
||||
case ERROR_READ:
|
||||
printf("Can not read %s\n", file_name);
|
||||
break;
|
||||
case ERROR_MEM:
|
||||
printf("Not enough memory\n");
|
||||
break;
|
||||
}
|
||||
if (ret != SUCCESS){
|
||||
free(x);
|
||||
free(y);
|
||||
return 3;
|
||||
}
|
||||
t = clock();
|
||||
ret = task03(x0, n, x, y, &res);
|
||||
if (ret == 1){ // ПРОВЕРЯЕМ ОШИБКУ в ret
|
||||
printf("Division by zero occurs. Most likely, were two identical points in file.");
|
||||
free(x);
|
||||
free(y);
|
||||
return 4;
|
||||
}
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], 3, res, t);
|
||||
free(x);
|
||||
free(y);
|
||||
return 0;
|
||||
}
|
79
2025.04.18/dist/Ryabov_AD/task04.c
vendored
Normal file
79
2025.04.18/dist/Ryabov_AD/task04.c
vendored
Normal file
|
@ -0,0 +1,79 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include "massiv_io.h"
|
||||
#include "solve.h"
|
||||
|
||||
|
||||
int main(int argc, char*argv[]){
|
||||
double *x, *y, *d;
|
||||
int n, ret_f;
|
||||
double t, x0;
|
||||
double res;
|
||||
char *file_name;
|
||||
io_status ret;
|
||||
if (!(argc == 4 && sscanf(argv[1], "%lf", &x0) == 1 && sscanf(argv[2], "%d", &n) == 1)){
|
||||
printf("Usage %s\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (n <= 0){
|
||||
printf("With zero points impossible to plot graph\n");
|
||||
return 1;
|
||||
}
|
||||
file_name = argv[3];
|
||||
// Массив x
|
||||
x = (double *)malloc(n * sizeof(double));
|
||||
if (!x){
|
||||
printf("No pamyat\n");
|
||||
return 2;
|
||||
}
|
||||
// Массив y
|
||||
y = (double *)malloc(n * sizeof(double));
|
||||
if (!y){
|
||||
printf("No pamyat\n");
|
||||
free(x);
|
||||
return 2;
|
||||
}
|
||||
d = (double *)malloc(n * sizeof(double));
|
||||
if (!d){
|
||||
printf("No pamyat\n");
|
||||
free(x);
|
||||
free(y);
|
||||
return 2;
|
||||
}
|
||||
ret = read_file_4(x, y, d, n, file_name);
|
||||
switch (ret){
|
||||
case SUCCESS:
|
||||
break;
|
||||
case ERROR_OPEN:
|
||||
printf("Can not open %s\n", file_name);
|
||||
break;
|
||||
case ERROR_READ:
|
||||
printf("Can not read %s\n", file_name);
|
||||
break;
|
||||
case ERROR_MEM:
|
||||
printf("Not enough memory\n");
|
||||
break;
|
||||
}
|
||||
if (ret != SUCCESS){
|
||||
free(x);
|
||||
free(y);
|
||||
free(d);
|
||||
return 3;
|
||||
}
|
||||
t = clock();
|
||||
ret_f = task04(x0, n, x, y, d, &res);
|
||||
if (ret_f){
|
||||
printf("Division by zero occurs. Most likely, were two identical points in file.");
|
||||
free(x);
|
||||
free(y);
|
||||
free(d);
|
||||
return 4;
|
||||
}
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], 4, res, t);
|
||||
free(x);
|
||||
free(y);
|
||||
free(d);
|
||||
return 0;
|
||||
}
|
25
2025.04.18/dist/Ryabov_AD/task05.c
vendored
Normal file
25
2025.04.18/dist/Ryabov_AD/task05.c
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "massiv_io.h"
|
||||
#include "solve.h"
|
||||
|
||||
|
||||
int main(int argc, char*argv[]){
|
||||
double t, x0, eps;
|
||||
double res;
|
||||
if (!(argc == 3 && sscanf(argv[1], "%lf", &x0) == 1 && sscanf(argv[2], "%lf", &eps) == 1)){
|
||||
printf("Usage %s\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (eps <= 0){
|
||||
printf("Negative precision and 0 not accepted");
|
||||
return 1;
|
||||
}
|
||||
t = clock();
|
||||
res = task05(x0, eps);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
printf ("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], 5, res, fabs(res - sin(x0)), t);
|
||||
return 0;
|
||||
}
|
25
2025.04.18/dist/Ryabov_AD/task06.c
vendored
Normal file
25
2025.04.18/dist/Ryabov_AD/task06.c
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "massiv_io.h"
|
||||
#include "solve.h"
|
||||
|
||||
|
||||
int main(int argc, char*argv[]){
|
||||
double t, x0, eps;
|
||||
double res;
|
||||
if (!(argc == 3 && sscanf(argv[1], "%lf", &x0) == 1 && sscanf(argv[2], "%lf", &eps) == 1)){
|
||||
printf("Usage %s\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (eps <= 0){
|
||||
printf("Negative precision and 0 not accepted");
|
||||
return 1;
|
||||
}
|
||||
t = clock();
|
||||
res = task06(x0, eps);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
printf ("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], 6, res, fabs(res - cos(x0)), t);
|
||||
return 0;
|
||||
}
|
25
2025.04.18/dist/Ryabov_AD/task07.c
vendored
Normal file
25
2025.04.18/dist/Ryabov_AD/task07.c
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "massiv_io.h"
|
||||
#include "solve.h"
|
||||
|
||||
|
||||
int main(int argc, char*argv[]){
|
||||
double t, x0, eps;
|
||||
double res;
|
||||
if (!(argc == 3 && sscanf(argv[1], "%lf", &x0) == 1 && sscanf(argv[2], "%lf", &eps) == 1)){
|
||||
printf("Usage %s\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (eps <= 0){
|
||||
printf("Negative precision and 0 not accepted");
|
||||
return 1;
|
||||
}
|
||||
t = clock();
|
||||
res = task07(x0, eps);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
printf ("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], 7, res, fabs(res - exp(x0)), t);
|
||||
return 0;
|
||||
}
|
29
2025.04.18/dist/Ryabov_AD/task08.c
vendored
Normal file
29
2025.04.18/dist/Ryabov_AD/task08.c
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "massiv_io.h"
|
||||
#include "solve.h"
|
||||
|
||||
|
||||
int main(int argc, char*argv[]){
|
||||
double t, x0, eps;
|
||||
double res;
|
||||
if (!(argc == 3 && sscanf(argv[1], "%lf", &x0) == 1 && sscanf(argv[2], "%lf", &eps) == 1)){
|
||||
printf("Usage %s\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (x0 <= 0){
|
||||
printf("Na mehmate ln dlya nepolozhitelnyh ne opredelen");
|
||||
return 2;
|
||||
}
|
||||
if (eps <= 0){
|
||||
printf("Negative precision and 0 not accepted");
|
||||
return 1;
|
||||
}
|
||||
t = clock();
|
||||
res = task08(x0, eps);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
printf ("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], 8, res, fabs(res - log(x0)), t);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue