Task 1 is donemake cleanmake cleanmake clean

This commit is contained in:
AZEN-SGG 2025-04-10 18:16:45 +03:00
parent cb3f70cbd6
commit de2b2eb48d
3 changed files with 19 additions and 52 deletions

View file

@ -10,7 +10,7 @@ WFLAGS = -W -Wall -Wextra -Wunused -Wempty-body -Wlogical-op \
-pedantic-errors -Wfloat-equal -Wwrite-strings -Wno-long-long \ -pedantic-errors -Wfloat-equal -Wwrite-strings -Wno-long-long \
-Wstrict-prototypes -Wmissing-field-initializers -Wpointer-sign -Wstrict-prototypes -Wmissing-field-initializers -Wpointer-sign
TARGET = a14.out TARGET = a.out
OBJ = main.o solve.o array_io.o init_f.o matrix.o OBJ = main.o solve.o array_io.o init_f.o matrix.o
%.o: %.c %.o: %.c

View file

@ -6,14 +6,15 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#define EPS 1.2e-16
// c - changes in rows // c - changes in rows
int t14_solve(int n, double * restrict A, double * restrict X, int * restrict c) int t14_solve(int n, double * restrict A, double * restrict X, int * restrict c)
{ {
double norm = get_matrix_norm(n, A); double norm = get_matrix_norm(n, A);
double eps = DBL_EPSILON*norm; double eps = EPS*norm;
if (norm < DBL_EPSILON) // printf("NORM = %lf EPS = %lf\n", norm, eps);
return SINGULAR;
// Проходимся по главным минорам // Проходимся по главным минорам
for (int k = 0; k < n; ++k) { for (int k = 0; k < n; ++k) {
@ -36,7 +37,7 @@ int t14_solve(int n, double * restrict A, double * restrict X, int * restrict c)
// printf("Maximum = %lf i = %d j = %d\n", maximum, max_i, max_j); // printf("Maximum = %lf i = %d j = %d\n", maximum, max_i, max_j);
// Если максимальный по модулю элемент равен нулю, значит матрица вырождена // Если максимальный по модулю элемент равен нулю, значит матрица вырождена
if (fabs(maximum) < eps) if (fabs(maximum) <= eps)
return SINGULAR; return SINGULAR;
// Меняем строки местами, если максимум находится не в k строке // Меняем строки местами, если максимум находится не в k строке

View file

@ -6,14 +6,15 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#define EPS 1.2e-16
// c - changes in rows // c - changes in rows
int t14_solve(int n, double * restrict A, double * restrict X, int * restrict c) int t14_solve(int n, double * restrict A, double * restrict X, int * restrict c)
{ {
double norm = get_matrix_norm(n, A); double norm = get_matrix_norm(n, A);
double eps = DBL_EPSILON*norm; double eps = EPS*norm;
if (norm < DBL_EPSILON) // printf("NORM = %lf EPS = %lf\n", norm, eps);
return SINGULAR;
// Проходимся по главным минорам // Проходимся по главным минорам
for (int k = 0; k < n; ++k) { for (int k = 0; k < n; ++k) {
@ -36,7 +37,7 @@ int t14_solve(int n, double * restrict A, double * restrict X, int * restrict c)
// printf("Maximum = %lf i = %d j = %d\n", maximum, max_i, max_j); // printf("Maximum = %lf i = %d j = %d\n", maximum, max_i, max_j);
// Если максимальный по модулю элемент равен нулю, значит матрица вырождена // Если максимальный по модулю элемент равен нулю, значит матрица вырождена
if (fabs(maximum) < eps) if (fabs(maximum) <= eps)
return SINGULAR; return SINGULAR;
// Меняем строки местами, если максимум находится не в k строке // Меняем строки местами, если максимум находится не в k строке
@ -73,8 +74,9 @@ int t14_solve(int n, double * restrict A, double * restrict X, int * restrict c)
c[max_j] = c[k]; c[max_j] = c[k];
c[k] = swap_temp; c[k] = swap_temp;
for (int in = 0; in < n*n; in+=n) for (int i = 0; i < n; i++)
{ {
const int in = i*n;
double swap = A[in + k]; double swap = A[in + k];
A[in + k] = A[in + max_j]; A[in + k] = A[in + max_j];
A[in + max_j] = swap; A[in + max_j] = swap;
@ -110,50 +112,14 @@ int t14_solve(int n, double * restrict A, double * restrict X, int * restrict c)
c[i] = i; c[i] = i;
i = swap_int; i = swap_int;
for (int ij = in, kj = kn; ij < in+n; ++ij, ++kj)
{
double swap_temp = X[ij];
X[ij] = X[kj];
X[kj] = swap_temp;
}
}
}
// Возвращаем строки назад
/* for (int k = 0; k < n; ++k)
{
int pnt_cur = c[k];
if (pnt_cur != k)
{
int pnt_nxt = 0;
for (int j = 0; j < n; ++j) for (int j = 0; j < n; ++j)
{ {
int loc_cur = pnt_cur; double swap_temp = X[in+j];
double temp_cur = X[k*n + j]; X[in+j] = X[kn+j];
double temp_nxt = 0; X[kn+j] = swap_temp;
}
do {
temp_nxt = X[loc_cur*n + j];
X[loc_cur*n + j] = temp_cur;
temp_cur = temp_nxt;
loc_cur = c[loc_cur];
} while (loc_cur != k);
X[k*n + j] = temp_cur;
} }
do {
pnt_nxt = c[pnt_cur];
c[pnt_cur] = pnt_cur;
pnt_cur = pnt_nxt;
} while (pnt_nxt != k);
c[k] = k;
} }
}*/
return 0; return 0;
} }