Make it possible to augment a matrix

main
Micke Nordin 2 years ago
parent 2df8387cf4
commit c2f65038bf
Signed by: micke
GPG Key ID: 014B273D614BE877

@ -11,6 +11,7 @@ private:
uint64_t entry_dimension;
vector *entries;
bool err;
bool augmented = false;
public:
matrix(const uint64_t num_entries, const uint64_t entry_dimension) {
@ -38,6 +39,24 @@ public:
this->entries = NULL;
this->err = true;
}
const matrix augment(vector v) const {
matrix m = *this;
if (v.get_dimention() != this->get_num_entries()) {
m.err = true;
return m;
}
for (uint64_t i = 0; i < m.get_num_entries(); i++) {
vector old = m[i];
vector n(old.get_dimention() + 1);
for (uint64_t j = 0; j < old.get_dimention(); j++)
n[j] = old[j];
n[old.get_dimention()] = v[i];
m[i] = n;
}
m.entry_dimension = m.entry_dimension + 1;
m.augmented = true;
return m;
}
const uint64_t get_num_entries() const { return this->num_entries; }
const uint64_t get_entry_dimension() const { return this->entry_dimension; }
const cnumber determinant() const {
@ -217,13 +236,15 @@ public:
oss << std::setw(padding) << "|";
symbols[1] = oss.str();
symbols[2] = "|";
for (int i = 0; i < 3; i++) {
int len = symbols[i].length() - 1;
char cur = symbols[i][0];
if (cur != last) {
os << symbols[i];
}
last = symbols[i][len];
bool print = true;
for (int k = 0; k < 3; k++) {
int len = symbols[k].length() - 1;
char cur = symbols[k][0];
if (cur != last || (m.augmented && j == m[i].get_dimention() - 1 && print)) {
print = false;
os << symbols[k];
}
last = symbols[k][len];
}
}
if (i != m.num_entries - 1)

Loading…
Cancel
Save