diff --git a/Report.docx b/Report.docx new file mode 100644 index 0000000..200da11 Binary files /dev/null and b/Report.docx differ diff --git a/Sorts/Report.docx b/Sorts/Report.docx new file mode 100644 index 0000000..200da11 Binary files /dev/null and b/Sorts/Report.docx differ diff --git a/Sorts/SortsUnn.cpp b/Sorts/SortsUnn.cpp new file mode 100644 index 0000000..8cd0ed6 --- /dev/null +++ b/Sorts/SortsUnn.cpp @@ -0,0 +1,284 @@ +#include "stdio.h" +#include "cstdlib" +#include "locale.h" +#include "time.h" +#include "string.h" + +int menu() { + int v; + printf_s("1. Задать массив\n2. Отсортировать массив\n3. Выход\n"); + scanf_s("%d", &v); + return v; +} + +void swap(float* a, float* b) { + float tmp = *a; + *a = *b; + *b = tmp; +} + +void bubble_sort(float* arr, int n) { + int i, j; + int flag = 0; + for (i = 0; i < n; i++) { + flag = 0; + for (j = 0; j < n - 1 - i; j++) { + if (arr[j] > arr[j + 1]) { + swap(&arr[j], &arr[j + 1]); + flag = 1; + } + } + if (flag == 0) + break; + } +} + + +void merge(float* in, float* out, int l, int m, int r) { + int l1, l2; + int index = 0; + l1 = l; + l2 = m + 1; + while (l1 <= m && l2 <= r) { + if (in[l1] <= in[l2]) { + out[index++] = in[l1++]; + } + else { + out[index++] = in[l2++]; + } + } + while (l1 > m && l2 <= r) { + out[index++] = in[l2++]; + } + while (l2 > r && l1 <= m) { + out[index++] = in[l1++]; + } + for (int i = 0; i < index; i++) { + in[l + i] = out[i]; + } +} + +void merge_sort(float* arr, float* tmp, int l, int r) { + int m = l + ((r - l) / 2); + if (l == r) { + return; + } + merge_sort(arr, tmp, l, m); + merge_sort(arr, tmp, m + 1, r); + merge(arr, tmp, l, m, r); +} + + + +void countByte(unsigned int* arr, int size, int count[256], int Byte) { //исхоодный массив, размер массива, символьный массив, текущий разряд + int tmp1, tmp2; //временная переменная + int i; + unsigned char* arrc = 0; // символьный массив + arrc = (unsigned char*)malloc(sizeof(unsigned char) * size); //?????????????/ + int bias; //cмещение (нужен для отрицательных чисел, потому что (-5 = -5 + bias) в беззнаковой системе + bias = sizeof(unsigned int); //он хранит размер беззнакового инта + arrc = (unsigned char*)arr; //делаю массив символов из предыдущего массива + for (i = 0; i < 256; i++) { //заполняю вспомогательный массив нулями + count[i] = 0; + } + for (i = 0; i < size; i++) { //накидываю сколько раз определенное число входило в массив + count[arrc[i * bias + Byte]]++; //?????????? + } + tmp1 = count[0]; //распределяю по индескам куда ставить числа + count[0] = 0; + for (i = 1; i < 256; i++) { + tmp2 = count[i]; + count[i] = count[i - 1] + tmp1; //теперь в count лежат индексы, на которые нужно ставить числа каждого индекса массива + tmp1 = tmp2; + } + +} + +void radix_sort(unsigned int* arr, int size, unsigned* arr_tmp) { + unsigned char* arrc = (unsigned char*)arr; //копирую массив чаров + int count[256]; + int sizetype = sizeof(unsigned int); + int i, j; + for (i = 0; i < sizetype; i++) { + countByte(arr, size, count, i); //где i - это номер разряда + for (j = 0; j < size; j++) { //Заполняем числами с выведенной индексацией + arr_tmp[count[arrc[j * sizetype + i]]++] = arr[j]; + } + for (j = 0; j < size; j++) { //Из временного массива в основной + arr[j] = arr_tmp[j]; + } + } +} + +void radixFloat(float* arr, float* arr_tmp, int N) { + int count = 0; + int i = 0; + radix_sort((unsigned int*)arr, (unsigned int)N, (unsigned int*)arr_tmp); + while (i < N) { //Считаем количество положительных чисел + if (arr[i] >= 0) { + count++; + } + i++; + } + for (i = 0; i < count; i++) { + arr_tmp[N - count + i] = arr[i]; + } + count = N - count; + for (count = count--; count >= 0; count--) { + arr_tmp[count] = arr[i++]; + } + + for (i = 0; i < N; i++) { + arr[i] = arr_tmp[i]; + } +} + +int compare(const void* a, const void* b) +{ + const float* ad, * bd; + ad = (const float*)a; + bd = (const float*)b; + + if ((*ad - *bd) < 0) return -1; + else + { + if ((*ad - *bd) > 0) return 1; + else return 0; + } +} + +int check(float* arr, float* arrforsort, int n) { + int f = 0; + int i = 0; + float* qarr = 0; + qarr = (float*)malloc(sizeof(float) * n); + qarr = arr; + qsort(qarr, n, sizeof(float), compare); + for (i = 0; i < n; i++) { + if (qarr[i] != arrforsort[i]) { + return 0; + } + } + return 1; +} + + +int main() +{ + int v, n, v2, v3, i; + float* arrforsorts = 0; + float* arr = 0; + clock_t start, end; + setlocale(LC_ALL, "Rus"); + while (true) { + int f = 0; + printf("Введите цифру, которая ссответсвует вашему выбору:\n"); + v = menu(); + switch (v) { + case(1): + { + + printf("Укажите размерность массива:\n"); + scanf_s("%d", &n); + arr = (float*) malloc(sizeof(float) * n); + arrforsorts = (float*)malloc(sizeof(float) * n); + + printf("1. Заполнить с клавиатуры\n2. Заполнить автоматически (-1000 <= рандом < 1000)\n"); + scanf_s("%d", &v2); + switch (v2) { + case(1): + { + printf("Введите %d чисел:\n", n); + for (i = 0; i < n; i++) { + printf("%d. ", i + 1); + scanf_s("%f", &arr[i]); + arrforsorts[i] = arr[i]; + } + continue; + } + case(2): + { + for (i = 0; i < n; i++) { + arr[i] = (((float) rand() / RAND_MAX) * 1000) - (((float)rand() / RAND_MAX) * 1000); + arrforsorts[i] = arr[i]; + } + continue; + } + + default: + { + free(arrforsorts); + free(arr); + continue; + } + } + } + case (2): + { + printf("Выберите номер сортировки:\n1. Сортировка пузырьком\n2. Сортировка слиянием\n3. Поразрядная сортировка\n"); + scanf_s("%d", &v3); + switch(v3) { + case(1): + { + start = clock(); + bubble_sort(arrforsorts , n); + end = clock(); + if (check(arr, arrforsorts, n) == 1) { + printf_s("OK\n"); + printf_s("%d\n", (end - start)); + } + else printf_s("ERORR!\n"); + continue; + } + case(2): + { + float* out = 0; + out = (float*)malloc(sizeof(float)*n); + start = clock(); + merge_sort(arrforsorts, out, 0, n-1); + end = clock(); + if (check(arr, arrforsorts, n) == 1) { + printf_s("OK\n"); + printf_s("%d\n", (end - start)); + } + else printf_s("ERORR!\n"); + free(out); + continue; + } + case(3): + { + float* arr_tmp = (float*)malloc(sizeof(float) * n); + start = clock(); + radixFloat(arrforsorts, arr_tmp, n); + end = clock(); + if (check(arr, arrforsorts, n) == 1) { + printf_s("OK\n"); + printf_s("%d\n", (end - start)); + } + else printf_s("ERORR!\n"); + free(arr_tmp); + continue; + } + } + } + case(3): + { + f = 1; + } + default: + { + free(arr); + break; + } + } + if (f == 1) { + + break; + } + free(arrforsorts); + free(arr); + } + + +} + diff --git a/gauss/Debug/main.exe b/gauss/Debug/main.exe new file mode 100644 index 0000000..d8b359c Binary files /dev/null and b/gauss/Debug/main.exe differ diff --git a/gauss/Debug/main.pdb b/gauss/Debug/main.pdb new file mode 100644 index 0000000..bcd0f19 Binary files /dev/null and b/gauss/Debug/main.pdb differ diff --git a/gauss/gauss.sln b/gauss/gauss.sln new file mode 100644 index 0000000..47ef7f9 --- /dev/null +++ b/gauss/gauss.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32802.440 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gauss", "gauss\gauss.vcxproj", "{50DFADFA-4BA5-4867-AD98-389099A4F460}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {50DFADFA-4BA5-4867-AD98-389099A4F460}.Debug|x64.ActiveCfg = Debug|x64 + {50DFADFA-4BA5-4867-AD98-389099A4F460}.Debug|x64.Build.0 = Debug|x64 + {50DFADFA-4BA5-4867-AD98-389099A4F460}.Debug|x86.ActiveCfg = Debug|Win32 + {50DFADFA-4BA5-4867-AD98-389099A4F460}.Debug|x86.Build.0 = Debug|Win32 + {50DFADFA-4BA5-4867-AD98-389099A4F460}.Release|x64.ActiveCfg = Release|x64 + {50DFADFA-4BA5-4867-AD98-389099A4F460}.Release|x64.Build.0 = Release|x64 + {50DFADFA-4BA5-4867-AD98-389099A4F460}.Release|x86.ActiveCfg = Release|Win32 + {50DFADFA-4BA5-4867-AD98-389099A4F460}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CCA00ACE-C479-4CA7-9DB0-7A20A7C2FED7} + EndGlobalSection +EndGlobal diff --git a/gauss/gauss/Debug/funcs.obj b/gauss/gauss/Debug/funcs.obj new file mode 100644 index 0000000..e6173bc Binary files /dev/null and b/gauss/gauss/Debug/funcs.obj differ diff --git a/gauss/gauss/Debug/gauss.log b/gauss/gauss/Debug/gauss.log new file mode 100644 index 0000000..73bfb5d --- /dev/null +++ b/gauss/gauss/Debug/gauss.log @@ -0,0 +1,24 @@ + gauss.cpp +C:\Users\pitza\source\repos\gauss\gauss\funcs.h(66,1): warning C4305: инициализация: усечение из "double" в "T" + with + [ + T=float + ] +C:\Users\pitza\source\repos\gauss\gauss\gauss.cpp(20): message : выполняется компиляция ссылки на экземпляр шаблон функции "void solver(int)" +C:\Users\pitza\source\repos\gauss\gauss\funcs.h(83,24): warning C4244: =: преобразование "int" в "T", возможна потеря данных + with + [ + T=float + ] +C:\Users\pitza\source\repos\gauss\gauss\funcs.h(54,1): warning C4305: инициализация: усечение из "double" в "T" + with + [ + T=float + ] +C:\Users\pitza\source\repos\gauss\gauss\funcs.h(148): message : выполняется компиляция ссылки на экземпляр шаблон функции "bool is_null(int,int,matrix &)" + with + [ + T=float + ] +C:\Users\pitza\source\repos\gauss\gauss\gauss.cpp(20): message : выполняется компиляция ссылки на экземпляр шаблон функции "void solver(int)" + gauss.vcxproj -> C:\Users\pitza\source\repos\gauss\Debug\main.exe diff --git a/gauss/gauss/Debug/gauss.obj b/gauss/gauss/Debug/gauss.obj new file mode 100644 index 0000000..af60083 Binary files /dev/null and b/gauss/gauss/Debug/gauss.obj differ diff --git a/gauss/gauss/Debug/main.exe.recipe b/gauss/gauss/Debug/main.exe.recipe new file mode 100644 index 0000000..def4059 --- /dev/null +++ b/gauss/gauss/Debug/main.exe.recipe @@ -0,0 +1,11 @@ + + + + + C:\Users\pitza\source\repos\gauss\Debug\main.exe + + + + + + \ No newline at end of file diff --git a/gauss/gauss/Debug/main.ilk b/gauss/gauss/Debug/main.ilk new file mode 100644 index 0000000..be07278 Binary files /dev/null and b/gauss/gauss/Debug/main.ilk differ diff --git a/gauss/gauss/Debug/main.tlog/CL.command.1.tlog b/gauss/gauss/Debug/main.tlog/CL.command.1.tlog new file mode 100644 index 0000000..acf593c Binary files /dev/null and b/gauss/gauss/Debug/main.tlog/CL.command.1.tlog differ diff --git a/gauss/gauss/Debug/main.tlog/CL.read.1.tlog b/gauss/gauss/Debug/main.tlog/CL.read.1.tlog new file mode 100644 index 0000000..6b1731c Binary files /dev/null and b/gauss/gauss/Debug/main.tlog/CL.read.1.tlog differ diff --git a/gauss/gauss/Debug/main.tlog/CL.write.1.tlog b/gauss/gauss/Debug/main.tlog/CL.write.1.tlog new file mode 100644 index 0000000..0797164 Binary files /dev/null and b/gauss/gauss/Debug/main.tlog/CL.write.1.tlog differ diff --git a/gauss/gauss/Debug/main.tlog/link.command.1.tlog b/gauss/gauss/Debug/main.tlog/link.command.1.tlog new file mode 100644 index 0000000..27aabfb Binary files /dev/null and b/gauss/gauss/Debug/main.tlog/link.command.1.tlog differ diff --git a/gauss/gauss/Debug/main.tlog/link.read.1.tlog b/gauss/gauss/Debug/main.tlog/link.read.1.tlog new file mode 100644 index 0000000..9027f1e Binary files /dev/null and b/gauss/gauss/Debug/main.tlog/link.read.1.tlog differ diff --git a/gauss/gauss/Debug/main.tlog/link.write.1.tlog b/gauss/gauss/Debug/main.tlog/link.write.1.tlog new file mode 100644 index 0000000..3ab6f28 Binary files /dev/null and b/gauss/gauss/Debug/main.tlog/link.write.1.tlog differ diff --git a/gauss/gauss/Debug/main.tlog/main.lastbuildstate b/gauss/gauss/Debug/main.tlog/main.lastbuildstate new file mode 100644 index 0000000..d411e48 --- /dev/null +++ b/gauss/gauss/Debug/main.tlog/main.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0: +Debug|Win32|C:\Users\pitza\source\repos\gauss\| diff --git a/gauss/gauss/Debug/matrix.obj b/gauss/gauss/Debug/matrix.obj new file mode 100644 index 0000000..85e96c6 Binary files /dev/null and b/gauss/gauss/Debug/matrix.obj differ diff --git a/gauss/gauss/Debug/vc142.idb b/gauss/gauss/Debug/vc142.idb new file mode 100644 index 0000000..deeb194 Binary files /dev/null and b/gauss/gauss/Debug/vc142.idb differ diff --git a/gauss/gauss/Debug/vc142.pdb b/gauss/gauss/Debug/vc142.pdb new file mode 100644 index 0000000..c2b04bf Binary files /dev/null and b/gauss/gauss/Debug/vc142.pdb differ diff --git a/gauss/gauss/Debug/vector.obj b/gauss/gauss/Debug/vector.obj new file mode 100644 index 0000000..6103619 Binary files /dev/null and b/gauss/gauss/Debug/vector.obj differ diff --git a/gauss/gauss/funcs.h b/gauss/gauss/funcs.h new file mode 100644 index 0000000..7fc4eb0 --- /dev/null +++ b/gauss/gauss/funcs.h @@ -0,0 +1,161 @@ +#include "vec.h" +#include "matrix.h" +#include + +template +bool was_using(int k, int n, vec& U) { + for (int i = 0; i < n; i++) { + if (U[i] == k) { + return true; + } + } + return false; +} + + +template +int search_max(int n, int ind, matrix& A, vec& U) { + T max; + int max_ind; + for (int i = 0; i < n; i++) { + if (!was_using(i, n, U)) { + max = A(i, ind); + max_ind = i; + } + } + + + for (int i = 0; i < n; i++) { + if (abs(max) <= abs(A(i, ind)) && !was_using(i, n, U)) { + max = A(i, ind); + max_ind = i; + } + } + return max_ind; +} + + +template +int search_max_for_result(int n, int ind, matrix& A) { + T max = A(0, ind); + int max_ind = 0; + for (int i = 0; i < n; i++) { + if (abs(max) <= abs(A(i, ind))) { + max = A(i, ind); + max_ind = i; + } + } + return max_ind; +} + + +template +bool is_null(int n, int ind, matrix& A) { + T eps = 10e-16; + for (int j = 0; j < n; j++) { + if (abs(A(ind, j)) - T(eps) > 0) + return false; + } + return true; +} + + + +template +void solver(int n) { + T eps = 10e-15; + matrix A(n); + vec B(n); + vec used(n); //ìàññèâ ñòðîê, êîòîðûå óæå èñïîëüçîâàëèñü â i-ûõ ñòîëáöàõ + cout << "Enter A:\n"; + A.set_matrix(n); + cout << "Enter B:\n"; + B.set_vec(n); + int ind_max; //èíäåêñ ìàêñèìàëüíîãî + T divid; + + for (int column = 0; column < n; column++) { + ind_max = search_max(n, column, A, used); + if (abs(A(ind_max, column)) - eps < 0) { + used[column] = -1; //òî åñòü âñå ñòðîêè â ýòîì ñòîëáöå ðàâíû íóëþ (ëèí.çàâèñèìûå åñòü) + continue; + } + used[column] = ind_max; + for (int i = 0; i < n; i++) { + if (i == ind_max) { + continue; + } + divid = A(i, column) / A(ind_max, column); + for (int j = column; j < n; j++) { + //if (A(i, j) != 0) { + A(i, j) -= A(ind_max, j) * divid; + // } + } + B[i] -= B[ind_max] * divid; + } + + cout << "\n"; + for (int i = 0; i < n; i++) { + cout << "\n"; + for (int j = 0; j < n; j++) { + cout << A(i, j) << " "; + } + } + } + + cout << "\n\n\n"; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (abs(A(i, j)) - eps < 0) { + cout << "0\t"; + } + else { + cout << A(i, j) << "\t"; + } + } + cout << "\t" << " | " << B[i] << "\n"; + } + + + if (!was_using(-1, n, used)) { //åñëè íå áûëî çàâèñèìûõ ñòðîê + cout << "\n\n\n Result:\n"; + for (int column = 0; column < n; column++) { + ind_max = search_max_for_result(n, column, A); + B[ind_max] /= A(ind_max, column); + cout << "x" << column + 1 << " = " << B[ind_max] << ";\n"; + } + } + else { //åñëè åñòü çàâèñèìûå ñòðîêè + cout << "\n\n\n Result:\n"; + for (int column = 0; column < n; column++) { + if (used[column] != -1) { + ind_max = search_max_for_result(n, column, A); + divid = A(ind_max, column); + B[ind_max] /= divid; + for (int j = 0; j < n; j++) { //ïðèâîæó ê åäèíè÷íîé ëåâóþ ÷àñòü + A(ind_max, j) /= divid; + } + } + } + int c = 0; + for (int i = 0; + i < n; i++) { //ñ÷åò÷èê ëèíåéíî çàâèñèìûõ (âïîñëåäñòâèè íóëåâûõ) ñòðîê (êîëè÷åñòâî ïàðàìåòðîâ) + if (used[i] == -1) { + c++; + } + } + for (int i = 0; i < n; i++) { + if (is_null(n, i, A)) { // ïðîâåðêà íà íóëåâóþ ñòðîêó + continue; + } + for (int j = 0; j < n - c; j++) { + if (A(i, j) == 1) { + cout << "x" << j + 1 << " = " << B[i]; + for (int k = 0; k < c; k++) { + cout << " - (" << A(i, n - k - 1) << ")t" << k + 1 << "\n"; + } + } + } + } + } +} diff --git a/gauss/gauss/gauss.cpp b/gauss/gauss/gauss.cpp new file mode 100644 index 0000000..98f2c34 --- /dev/null +++ b/gauss/gauss/gauss.cpp @@ -0,0 +1,26 @@ +#include +#include "funcs.h" +#include "matrix.h" +#include "vec.h" + +using namespace std; + +int main() { + int choice; + int n; + cout << "Enter typename:\n 1. double;\n 2. float;\n 3. int\n"; + cin >> choice; + cout << "Enter size: "; + cin >> n; + switch (choice) { + case 1: + solver(n); + break; + case 2: + solver(n); + break; + default: + return 0; + } + +} \ No newline at end of file diff --git a/gauss/gauss/gauss.vcxproj b/gauss/gauss/gauss.vcxproj new file mode 100644 index 0000000..dca5bb2 --- /dev/null +++ b/gauss/gauss/gauss.vcxproj @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {50dfadfa-4ba5-4867-ad98-389099a4f460} + gauss + 10.0 + main + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/gauss/gauss/gauss.vcxproj.filters b/gauss/gauss/gauss.vcxproj.filters new file mode 100644 index 0000000..c0b9229 --- /dev/null +++ b/gauss/gauss/gauss.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + + + Файлы заголовков + + + Файлы заголовков + + + Файлы заголовков + + + \ No newline at end of file diff --git a/gauss/gauss/gauss.vcxproj.user b/gauss/gauss/gauss.vcxproj.user new file mode 100644 index 0000000..0f14913 --- /dev/null +++ b/gauss/gauss/gauss.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/gauss/gauss/matrix.h b/gauss/gauss/matrix.h new file mode 100644 index 0000000..67e6328 --- /dev/null +++ b/gauss/gauss/matrix.h @@ -0,0 +1,67 @@ +#pragma once +#include +using namespace std; +template +class matrix { +private: + T** arr; + int n; // +public: + matrix(int _n) { + n = _n; + arr = new T * [n]; + for (int i = 0; i < n; i++) { + arr[i] = new T[n]; + } + } + + T& operator()(int ind1, int ind2) { + return arr[ind1][ind2]; + } + + matrix(const matrix& A) { + n = A.n; + arr = new T * [n]; + for (int i = 0; i < n; i++) { + arr[i] = new T[n]; + } + + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + arr[i][j] = A.arr[i][j]; + } + } + } + + + void set_matrix(int _n) { + n = _n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cin >> arr[i][j]; + } + } + }; + + void get_matrix(int _n) { + n = _n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cout << arr[i][j] << " "; + } + cout << "\n"; + } + } + + ~matrix() { + for (int i = 0; i < n; i++) { + delete[] arr[i]; + } + delete[] arr; + n = 0; + } +}; + + + + diff --git a/gauss/gauss/vec.h b/gauss/gauss/vec.h new file mode 100644 index 0000000..e9921ff --- /dev/null +++ b/gauss/gauss/vec.h @@ -0,0 +1,41 @@ +#pragma once +#include + +using namespace std; +template +class vec { +private: + int n; + T* arr; +public: + vec(int _n) { + n = _n; + arr = new T[n]; + for (int i = 0; i < n; i++) { + arr[i] = -2; + } + } + + T& operator[](int ind) { + return arr[ind]; + } + + void set_vec(int _n) { + n = _n; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + } + } + + void get_vec(int _n) { + n = _n; + for (int i = 0; i < n; i++) { + cout << "( " << arr[i] << " )\n"; + } + } + + ~vec() { + delete[] arr; + n = 0; + } +}; diff --git a/gauss/gauss/x64/Debug/funcs.obj b/gauss/gauss/x64/Debug/funcs.obj new file mode 100644 index 0000000..09a37f7 Binary files /dev/null and b/gauss/gauss/x64/Debug/funcs.obj differ diff --git a/gauss/gauss/x64/Debug/gauss.log b/gauss/gauss/x64/Debug/gauss.log new file mode 100644 index 0000000..21b3317 --- /dev/null +++ b/gauss/gauss/x64/Debug/gauss.log @@ -0,0 +1,9 @@ + funcs.cpp + gauss.cpp + matrix.cpp + vector.cpp + Создание кода... +gauss.obj : error LNK2019: ссылка на неразрешенный внешний символ "void __cdecl solver(int)" (??$solver@N@@YAXH@Z) в функции main. +gauss.obj : error LNK2019: ссылка на неразрешенный внешний символ "void __cdecl solver(int)" (??$solver@M@@YAXH@Z) в функции main. +gauss.obj : error LNK2019: ссылка на неразрешенный внешний символ "void __cdecl solver(int)" (??$solver@H@@YAXH@Z) в функции main. +C:\Users\pitza\source\repos\gauss\x64\Debug\main.exe : fatal error LNK1120: неразрешенных внешних элементов: 3 diff --git a/gauss/gauss/x64/Debug/gauss.obj b/gauss/gauss/x64/Debug/gauss.obj new file mode 100644 index 0000000..203934a Binary files /dev/null and b/gauss/gauss/x64/Debug/gauss.obj differ diff --git a/gauss/gauss/x64/Debug/main.tlog/CL.command.1.tlog b/gauss/gauss/x64/Debug/main.tlog/CL.command.1.tlog new file mode 100644 index 0000000..fcb487f Binary files /dev/null and b/gauss/gauss/x64/Debug/main.tlog/CL.command.1.tlog differ diff --git a/gauss/gauss/x64/Debug/main.tlog/CL.read.1.tlog b/gauss/gauss/x64/Debug/main.tlog/CL.read.1.tlog new file mode 100644 index 0000000..d25bfdf Binary files /dev/null and b/gauss/gauss/x64/Debug/main.tlog/CL.read.1.tlog differ diff --git a/gauss/gauss/x64/Debug/main.tlog/CL.write.1.tlog b/gauss/gauss/x64/Debug/main.tlog/CL.write.1.tlog new file mode 100644 index 0000000..22f1255 Binary files /dev/null and b/gauss/gauss/x64/Debug/main.tlog/CL.write.1.tlog differ diff --git a/gauss/gauss/x64/Debug/main.tlog/link-cvtres.read.1.tlog b/gauss/gauss/x64/Debug/main.tlog/link-cvtres.read.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/gauss/gauss/x64/Debug/main.tlog/link-cvtres.read.1.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/gauss/gauss/x64/Debug/main.tlog/link-cvtres.write.1.tlog b/gauss/gauss/x64/Debug/main.tlog/link-cvtres.write.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/gauss/gauss/x64/Debug/main.tlog/link-cvtres.write.1.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/gauss/gauss/x64/Debug/main.tlog/link-rc.read.1.tlog b/gauss/gauss/x64/Debug/main.tlog/link-rc.read.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/gauss/gauss/x64/Debug/main.tlog/link-rc.read.1.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/gauss/gauss/x64/Debug/main.tlog/link-rc.write.1.tlog b/gauss/gauss/x64/Debug/main.tlog/link-rc.write.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/gauss/gauss/x64/Debug/main.tlog/link-rc.write.1.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/gauss/gauss/x64/Debug/main.tlog/link.command.1.tlog b/gauss/gauss/x64/Debug/main.tlog/link.command.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/gauss/gauss/x64/Debug/main.tlog/link.command.1.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/gauss/gauss/x64/Debug/main.tlog/link.read.1.tlog b/gauss/gauss/x64/Debug/main.tlog/link.read.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/gauss/gauss/x64/Debug/main.tlog/link.read.1.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/gauss/gauss/x64/Debug/main.tlog/link.write.1.tlog b/gauss/gauss/x64/Debug/main.tlog/link.write.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/gauss/gauss/x64/Debug/main.tlog/link.write.1.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/gauss/gauss/x64/Debug/main.tlog/main.lastbuildstate b/gauss/gauss/x64/Debug/main.tlog/main.lastbuildstate new file mode 100644 index 0000000..701741f --- /dev/null +++ b/gauss/gauss/x64/Debug/main.tlog/main.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0: +Debug|x64|C:\Users\pitza\source\repos\gauss\| diff --git a/gauss/gauss/x64/Debug/main.tlog/unsuccessfulbuild b/gauss/gauss/x64/Debug/main.tlog/unsuccessfulbuild new file mode 100644 index 0000000..e69de29 diff --git a/gauss/gauss/x64/Debug/matrix.obj b/gauss/gauss/x64/Debug/matrix.obj new file mode 100644 index 0000000..ced36e4 Binary files /dev/null and b/gauss/gauss/x64/Debug/matrix.obj differ diff --git a/gauss/gauss/x64/Debug/vc142.idb b/gauss/gauss/x64/Debug/vc142.idb new file mode 100644 index 0000000..14f8e7c Binary files /dev/null and b/gauss/gauss/x64/Debug/vc142.idb differ diff --git a/gauss/gauss/x64/Debug/vc142.pdb b/gauss/gauss/x64/Debug/vc142.pdb new file mode 100644 index 0000000..9a84780 Binary files /dev/null and b/gauss/gauss/x64/Debug/vc142.pdb differ diff --git a/gauss/gauss/x64/Debug/vector.obj b/gauss/gauss/x64/Debug/vector.obj new file mode 100644 index 0000000..aafd657 Binary files /dev/null and b/gauss/gauss/x64/Debug/vector.obj differ diff --git a/gauss/x64/Debug/main.pdb b/gauss/x64/Debug/main.pdb new file mode 100644 index 0000000..5939cda Binary files /dev/null and b/gauss/x64/Debug/main.pdb differ diff --git a/pluses.cpp b/pluses.cpp new file mode 100644 index 0000000..86e0ae8 --- /dev/null +++ b/pluses.cpp @@ -0,0 +1,157 @@ +#include #include +#include +using namespace std; + + +class complex { +private: + double im, re; +public: + complex() { + im = 0; + re = 0; + } + complex(double _im,double _re) { + if (_im == 0) { + re = _re; + } + else { + re = _re; + im = _im; + } + } + + complex operator + (complex A) { + complex res; + res.im = im + A.im; + res.re = re + A.re; + } + + complex operator - (complex A) { + complex res; + res.im = im - A.im; + res.re = re - A.re; + } + + complex operator * (complex A) { + complex res; + res.im = re * A.im + im * A.re; + res.re = re*A.re - im*A.im; + } + + complex& operator = (complex &A) { + return (*this); + } + + +}; + +template +class Vec { +private: + int n; + T* arr; +public: + Vec(int _n) { + _n = n; + arr = new T[n]; + }; + + T& operator [] (int i) { + return arr[i]; + } + + Vec operator() (const Vec& vec1, const Vec& vec2) { + Vec A(vec1.n); + for (int i = 0; i < vec1.n; i++) { + A.arr[i] = vec1.arr[i] * vec2.arr[i]; + } + } + + void Set_vec() { + for (int i = 0; i < n; i++) { + cin >> arr[i]; + } + } + + + ~Vec() { + delete[] arr; + n = 0; + } +}; + + +template +class matrix { +private: + T** arr; + int n, m; //размерность +public: + matrix(int _n, int _m) { + n = _n; + m = _m; + arr = new T * [m]; + for (int i = 0; i < m; i++) { + arr[i] = new T[n]; + } + } + + T& operator()(int ind1, int ind2) { + return arr[ind1][ind2]; + } + + + void set_matrix(int _n, int _m) { ///НАДО РАНДОМОМ + n = _n; + m = _m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> arr[i][j]; + } + } + } + + void get_matrix(int _n) { + n = _n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cout << arr[i][j] << " "; + } + cout << "\n"; + } + } + + Vec operator () (matrix M,Vec A) { + Vec B(n); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + B[i] += M.arr[i][j]; + } + } + return B; + } + + ~matrix() { + for (int i = 0; i < n; i++) { + delete[] arr[i]; + } + delete[] arr; + n = 0; + } +}; + + + +int main() +{ + int n, m; + cin >> n >> m; + matrix A(n, m); + Vec B(n); + A.set_matrix(n, m); + B.Set_vec(); + VecC = (A, B); + +} + diff --git a/teilor/Report.docx b/teilor/Report.docx new file mode 100644 index 0000000..938e4b6 Binary files /dev/null and b/teilor/Report.docx differ diff --git a/teilor/main.c b/teilor/main.c new file mode 100644 index 0000000..a852d40 --- /dev/null +++ b/teilor/main.c @@ -0,0 +1,162 @@ +#include +#include +#define _USE_MATH_DEFINES +#include + +const int N = 101; + + +float mysin(float x, int ind, float ap) { //ap = a past == a i-1 + float ai; + ai = (-1) * x * x * ap / (2 * (float)ind * (2 * (float)ind + 1)); + return ai; +} + +float mysinR(float x, int ind, float an) { + float ai; + ai = (-an) * (2 * (float)ind + 2) * (2 * (float)ind + 3) / pow(x, 2); + return ai; +} + +float mycos(float x, int ind, float ap) { //ap = a past == a i-1 + float ai; + ai = (-1) * x * x * ap / (2 * (float)ind * (2 * (float)ind - 1)); + return ai; +} + +float mycosR(float x, int ind, float an) { + float ai; + ai = (-1) * ((2 * (float)ind) + 1) * ((2 * (float)ind) + 2) * an / (x * x); + return ai; +} + +float myexp(float x, int ind, float ap) { //ap = a past == a i-1 + float ai; + ai = x * ap / (float)ind; + return ai; +} + +float myexpR(float x, int ind, float an) { + float ai; + ai = (float)(ind + 1) * an / x; + return ai; +} + +float myln(float x, int ind, float ap) { //ap = a past == a i-1 + float ai; + ai = (-1) * x * (float)ind * ap / (float)(ind + 1); + return ai; +} + +float mylnR(float x, int ind, float an) { + float ai; + ai = (-1) * (float)(ind + 1) * an / ((float)(ind)*x); + return ai; +} + +float sumstr(float (*anything)(float, int, float), float x, float ap) { + float s = ap; + float ai; + for (int i = 1; i < N; i++) { + ai = anything(x, i, ap); + ap = ai; + s += ai; + } + return s; +} + +float sumback(float (*revers)(float, int, float), float (*straight)(float, int, float), float x, float ap) { + float ai; + float an; + int ind_a; + for (int i = 1; i < N; i++) { + ai = straight(x, i, ap); + if (fabsf(ai) - pow(10, -26) < 0) { + break; + } + else { + an = ai; + ind_a = i; + } + ap = ai; + } + + float s = an; + for (int i = ind_a - 1; i > 0; i--) { + ai = revers(x, i, an); + an = ai; + s += ai; + } + return s; +} + +int main() { + float sin0, cos0, exp0, ln0, x, sinl, cosl, expl, lnl, sin1, sin2, cos1, cos2, exp1, exp2, ln1, ln2; + int c; //choice + printf("Which fun you want to use?\n1.sin(x)\n2.cos(x)\n3.exp(x)\n4.ln(x)\n"); + scanf_s("%d", &c); + printf("Enter x: "); + scanf_s("%f", &x); + sin0 = x; + cos0 = 1; + exp0 = 1; + ln0 = x; + float err1; + float err2; + switch (c) { + case 1: + if (x == 0) { + x = 2 * (float)M_PI; + } + sin1 = sumstr(mysin, x, sin0); + sin2 = sumback(mysinR, mysin, x, sin0) + sin0; + printf("sin1 = %.10f\n", sin1); + printf("sin2 = %.10f\n", sin2); + printf("sin (standart) = %.10f\n", sinf(x)); + err1 = fabsf(sinf(x) - sin1) / fabsf(sinf(x)); + err2 = fabsf(sinf(x) - sin2) / fabsf(sinf(x)); + printf("Error for straight: %.10f\nError for back: %.10f", err1, err2); + break; + case 2: + if (x == 0) { + x = 2 * (float)M_PI; + } + cos1 = sumstr(mycos, x, cos0); + cos2 = sumback(mycosR, mycos, x, cos0) + cos0; + printf("cos1 = %.10f\n", cos1); + printf("cos2 = %.10f\n", cos2); + printf("cos (standart) = %.10f\n", cosf(x)); + fabsf(cosf(x) - cos1) / fabsf(cosf(x)); + err1 = fabsf(cosf(x) - cos1) / fabsf(cosf(x)); + err2 = fabsf(cosf(x) - cos2) / fabsf(cosf(x)); + printf("Error for straight: %.10f\nError for back: %.10f", err1, err2); + break; + case 3: + if (x == 0) { + x = 0; + } + exp1 = sumstr(myexp, x, exp0); + exp2 = sumback(myexpR, myexp, x, exp0) + exp0; + printf("exp1 = %.10f\n", exp1); + printf("exp2 = %.10f\n", exp2); + printf("exp (standart) = %.10f\n", expf(x)); + err1 = fabsf(expf(x) - exp1) / fabsf(expf(x)); + err2 = fabsf(expf(x) - exp1) / fabsf(expf(x)); + printf("Error for straight: %.10f\nError for back: %.10f", err1, err2); + break; + case 4: + if (x <= 0) { + printf("ERROR!"); + break; + } + ln1 = sumstr(myln, x, ln0); + ln2 = sumback(mylnR, myln, x, ln0) + ln0; + printf("ln1 = %.10f\n", ln1); + printf("ln2 = %.10f\n", ln2); + printf("ln (standart) = %.10f\n", logf(x+1)); + err1 = fabsf(logf(x + 1) - ln1) / fabsf(logf(x + 1)); + err2 = fabsf(logf(x + 1) - ln2) / fabsf(logf(x + 1)); + printf("Error for straight: %.10f\nError for back: %.10f", err1, err2); + break; + } +}