|
|
@ -22,8 +22,19 @@ public:
|
|
|
|
~matrix() {
|
|
|
|
~matrix() {
|
|
|
|
this->num_cols = 0;
|
|
|
|
this->num_cols = 0;
|
|
|
|
this->num_rows = 0;
|
|
|
|
this->num_rows = 0;
|
|
|
|
// free(this->cols);
|
|
|
|
free(this->cols);
|
|
|
|
// this->cols = NULL;
|
|
|
|
this->cols = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const cnumber determinant() const {
|
|
|
|
|
|
|
|
cnumber dsum(1,0);
|
|
|
|
|
|
|
|
cnumber osum(1,0);
|
|
|
|
|
|
|
|
vector diag = this->get_diagonal();
|
|
|
|
|
|
|
|
vector odiag = this->get_off_diagonal();
|
|
|
|
|
|
|
|
for (long long i = 0; i < diag.get_dimention(); i++) {
|
|
|
|
|
|
|
|
dsum = dsum * diag[i];
|
|
|
|
|
|
|
|
osum = osum * odiag[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return dsum - osum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const vector get_diagonal() const {
|
|
|
|
const vector get_diagonal() const {
|
|
|
|
long long diag_len = this->num_rows;
|
|
|
|
long long diag_len = this->num_rows;
|
|
|
@ -40,6 +51,21 @@ public:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const vector get_off_diagonal() const {
|
|
|
|
|
|
|
|
long long diag_len = this->num_rows;
|
|
|
|
|
|
|
|
if (this->num_cols < diag_len) {
|
|
|
|
|
|
|
|
diag_len = this->num_cols;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
vector v(diag_len);
|
|
|
|
|
|
|
|
for (long long i = 0; i < this->num_cols; i++) {
|
|
|
|
|
|
|
|
for (long long j = 0; j < this->num_rows; j++) {
|
|
|
|
|
|
|
|
if (i + j == this->num_rows - 1) {
|
|
|
|
|
|
|
|
v[i] = this->cols[i][j];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return v;
|
|
|
|
|
|
|
|
}
|
|
|
|
const vector get_row(long long index) const { return this->cols[index]; }
|
|
|
|
const vector get_row(long long index) const { return this->cols[index]; }
|
|
|
|
|
|
|
|
|
|
|
|
const vector get_column(long long index) const {
|
|
|
|
const vector get_column(long long index) const {
|
|
|
|