#include #include #include #include #include using namespace std; void GetMinor(vector > A, vector > &B, int x, int y, int size) { int _x = 0; int _y; for (int i = 0; i < size; ++i) { if (i != x) { _y = 0; for (int j = 0; j < size; ++j) { if (j != y) { B[_x][_y] = A[i][j]; _y++; } } _x++; } } } //Finding determinant of matrix (size x size) double FindDeterminant(vector > A, int size) { if (size == 1) { return A[0][0]; } else { double det = 0; vector > Minor(size - 1, vector (size - 1)); for (int i = 0; i < size; ++i) { GetMinor(A, Minor, 0, i, size); det += pow(-1, i) * A[0][i] * FindDeterminant(Minor, size - 1); } return det; } } double InsertFreeCoeff(vector > A, vector B, int size, int j) { for (int i = 0; i < size; ++i) { A[i][j] = B[i]; } double det = FindDeterminant(A, size); return det; } const int N = 10; double x[N] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; double y[N] = { -2.5, -6.7, -7.9, -8.5, -6.7, -6.3, -3.3, 0.3, 4.0, 9.2 }; int t = 20; void mnk() { double *b = NULL, *roots = NULL, **sum = NULL; int K, i, j, k; printf("Xi \t \t Yi\n"); for (int i = 0; i < N; i++) { printf("%.1f \t | \t %.1f\n", x[i], y[i]); } cout << endl << "rank k= "; cin >> K; cout << endl; b = new double[K + 1]; sum = new double *[K + 1]; for (int i = 0; i>>No roots!<<<" << endl; } else { cout << "det_A: " << det << endl; cout << "\n"; for (int i = 0; i < K + 1; ++i) { printf("det_%.d = %.2f\n", i + 1, InsertFreeCoeff(A, B, K + 1, i)); } cout << endl; cout << "Coefficients: " << endl; for (int i = 0; i < K + 1; ++i) { roots[i] = InsertFreeCoeff(A, B, K + 1, i) / det; cout << "A" << i << " = " << roots[i] << "\n"; } cout << endl << "Final equation: " << endl; cout << "F(X) = "; for (int i = 0; i < K + 1; ++i) { if (i < K) { printf("(%.3f)*X^%d + ", roots[i], i); } else { printf("(%.3f)*X^%d = 0\n", roots[i], i); } } } double val[50]; double q = -5; int M = 50; for (int i = 0; i < M; i++) { val[i] = 0; for (int p = 0; p < K + 1; p++) { val[i] += roots[p] * pow((double)q, p); } q = q + 0.5; } q = -5; glLineWidth(2); glBegin(GL_LINE_STRIP); glColor3f(1.0, 0.0, 0.0); for (int i = 0; i <= M; i++) { glVertex2d(q * t, val[i] * t); q = q + 0.5; } glEnd(); } void display() { //координатная плоскость glColor3f(0.0, 1.0, 0.0); glBegin(GL_LINES); glVertex2f(-550, 0); glVertex2f(550, 0); glEnd(); glBegin(GL_LINES); glVertex2f(0, 150); glVertex2f(0, -150); glEnd(); glPointSize(2.0); for (int i = -550; i < 550; i = i + 10) { if (i == 0) { glPointSize(4.0); glBegin(GL_POINTS); glColor3f(1.0, 1.0, 1.0); glVertex2d(i, 0); glEnd(); } else { glPointSize(2.0); glBegin(GL_POINTS); glColor3f(1.0, 1.0, 1.0); glVertex2d(i, 0); glEnd(); } } for (int i = -150; i < 150; i = i + 10) { if (i == 0) { glPointSize(4.0); glBegin(GL_POINTS); glColor3f(1.0, 1.0, 1.0); glVertex2d(0, i); glEnd(); } else { glPointSize(2.0); glBegin(GL_POINTS); glColor3f(1.0, 1.0, 1.0); glVertex2d(0, i); glEnd(); } } //отмечаем точки и соединяем glPointSize(5.0); for (int i = 0; i < N; i++) { glBegin(GL_POINTS); glColor3f(0.0, 0.0, 1.0); glVertex2d(x[i] * t, y[i] * t); glEnd(); } glBegin(GL_LINE_STRIP); glColor3f(1.0, 0.0, 1.0); for (int i = 0; i