27 Matrix makeMatrix(
size_t colCount,
const char* entries) {
29 istringstream in(entries);
34 for (
size_t col = 1; col < colCount; ++col)
49 istringstream in(entries);
52 vec.resize(vec.getSize() + 1);
53 vec[vec.getSize() - 1] = entry;
182 Matrix mat = makeMatrix(5,
186 Matrix red = makeMatrix(5,
239 Matrix mat = makeMatrix(3,
256 Matrix mat = makeMatrix(6,
286 Matrix mat = makeMatrix(6,
287 "13 -171 29 41 37 17\n"
288 "11 61 -278 131 19 23\n"
289 "-3 53 123 -317 41 7\n"
290 "11 97 23 47 -297 41\n"
291 "13 19 11 37 61 -143\n");
306 Matrix rhs = makeMatrix(2,
310 bool hasSolution =
solve(lhs, lhs, rhs);
318 Matrix rhs = makeMatrix(1,
"5\n14\n23\n");
320 bool hasSolution =
solve(sol, lhs, rhs);
323 ASSERT_EQ(sol, makeMatrix(1,
"1\n2\n0\n0"));
327 Matrix lhs = makeMatrix(1,
"2");
328 Matrix rhs = makeMatrix(2,
"-1 8");
330 bool hasSolution =
solve(sol, lhs, rhs);
333 ASSERT_EQ(sol, makeMatrix(2,
"-1/2\n4\n"));
338 " 13 -171 29 41 37 17\n"
339 " 11 61 -278 131 19 23\n"
340 " -3 53 123 -317 41 7\n"
341 " 11 97 23 47 -297 41\n"
342 " 13 19 11 37 61 -143\n";
344 pr << makeMatrix(6, str);
376 for (
size_t dim = 0; dim < 5; ++dim) {
407 (makeMatrix(3,
"1 2 1\n1 4 1\n2 2 1\n2 4 1")));
410 (makeMatrix(3,
"1 2 0\n1 4 2\n2 2 3\n2 4 5")));
413 (makeMatrix(3,
"5 -1 6\n 13 -5 5\n -14 5 -7\n -6 1 -8")));
415 (makeMatrix(4,
"-17 -15 -16 29\n -16 7 -24 18\n"
416 "-2 -10 27 -14\n -1 12 19 -25")));
void multiplyRow(Matrix &mat, size_t row, const mpq_class &mult)
Multiplies row row with mult.
bool solve(Matrix &sol, const Matrix &lhs, const Matrix &rhs)
Sets sol to some matrix such that lhs*sol=rhs and returns true if such a matrix exists.
mpq_class getParallelogramAreaSq(const Matrix &mat)
Returns the square of the area of the parallelogram whose vertices are the 4 rows of mat.
bool isParallelogram(const Matrix &mat)
Returns true if the rows of mat are the (4) vertices of a parallelogram.
void addMultiplyRow(Matrix &mat, size_t resultRow, size_t sourceRow, const mpq_class &mult)
Adds mult times row sourceRow to row resultRow of mat.
bool rowReduce(Matrix &mat)
Reduces mat to row-echelon form, i.e.
void swapRows(Matrix &mat, size_t row1, size_t row2)
Swaps row row1 and row row2 of mat.
void nullSpace(Matrix &basis, const Matrix &matParam)
Sets the columns of basis to a basis of the null space of mat.
mpq_class determinant(const Matrix &mat)
Returns the determinant of mat.
void subMatrix(Matrix &sub, const Matrix &mat, size_t rowBegin, size_t rowEnd, size_t colBegin, size_t colEnd)
Sets sub to the sub-matrix of mat with rows in the interval [rowBegin, rowEnd) and columns in the int...
void rowReduceFully(Matrix &mat)
Reduces mat to reduced row-echelon form, i.e.
bool inverse(Matrix &inv, const Matrix &mat)
Sets inv to the inverse of mat.
void transpose(Matrix &trans, const Matrix &mat)
Sets trans to the transpose of mat.
#define ASSERT_TRUE(VALUE)
#define ASSERT_FALSE(VALUE)
void resize(size_t rowCount, size_t colCount)
Set the number of rows and columns.
size_t getColCount() const
size_t getRowCount() const
#define TEST_SUITE(SUITE)
void swap(hashtable< _Val, _Key, _HF, _Extract, _EqKey, _All > &__ht1, hashtable< _Val, _Key, _HF, _Extract, _EqKey, _All > &__ht2)