File tree Expand file tree Collapse file tree 3 files changed +29
-6
lines changed
Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -175,11 +175,15 @@ int main() {
175175
176176 mult3 *= 6 ;
177177 mult3.print ();
178+
178179 Matrix det_test ({
179180 {2 , 4 , 3 },
180181 {5 , 7 , 8 },
181182 {6 , 9 , 1 },
182183 });
183184
184- cout << det_test.determinant () << endl;
185+ cout << det_test.determinant () << endl << endl;
186+
187+ det_test.minor_matrix ().print ();
188+ det_test.algebraic_additions ().print ();
185189}
Original file line number Diff line number Diff line change @@ -148,18 +148,34 @@ const double Matrix::determinant() {
148148 }
149149 default : {
150150 for (int i = 0 ; i < arr.size (); i++) {
151- if (i % 2 ) {
152- det -= arr[i][0 ] * this ->minor (i, 0 ).determinant ();
153- } else {
154- det += arr[i][0 ] * this ->minor (i, 0 ).determinant ();
155- }
151+ det += (i % 2 ? -1 : 1 ) * arr[i][0 ] * this ->minor (i, 0 ).determinant ();
156152 }
157153 break ;
158154 }
159155 }
160156 return det;
161157}
162158
159+ Matrix Matrix::minor_matrix () {
160+ Matrix temp (arr.size ());
161+ for (int y = 0 ; y < arr.size (); y ++) {
162+ for (int x = 0 ; x < arr.size (); x++) {
163+ temp.set (x, y, this ->minor (y, x).determinant ());
164+ }
165+ }
166+ return temp;
167+ }
168+
169+ Matrix Matrix::algebraic_additions () {
170+ Matrix temp = this ->minor_matrix ();
171+ for (int x = 0 ; x < arr.size (); x++) {
172+ for (int y = 0 ; y < arr.size (); y++) {
173+ if ((x + y) % 2 ) temp.arr [y][x] *= -1 ;
174+ }
175+ }
176+ return temp;
177+ }
178+
163179// операторы
164180
165181Matrix& Matrix::operator +=(const Matrix& m) {
Original file line number Diff line number Diff line change @@ -12,15 +12,18 @@ class Matrix {
1212
1313 public:
1414 // конструтроры (не лего)
15+
1516 Matrix (unsigned int size = 1 , double def = 0 );
1617 Matrix (vector <vector <double >> temp);
1718
1819 // сеттеры
20+
1921 Matrix& set (unsigned int x, unsigned int y, double value);
2022 Matrix& set (vector <vector <double >> temp);
2123 Matrix& set (Matrix& m);
2224
2325 // геттеры
26+
2427 double get (unsigned int x, unsigned int y);
2528 const unsigned int size ();
2629 const double determinant ();
You can’t perform that action at this time.
0 commit comments