Engauge Digitizer  2
Matrix.h
1 /******************************************************************************************************
2  * (C) 2016 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #ifndef MATRIX_H
8 #define MATRIX_H
9 
10 #include <QString>
11 #include <QVector>
12 
14 class Matrix
15 {
16 public:
18  Matrix(int N);
19 
21  Matrix (int rows, int cols);
22 
24  Matrix (const Matrix &other);
25 
27  Matrix &operator= (const Matrix &matrix);
28 
30  int cols () const;
31 
33  double determinant () const;
34 
36  double get (int row, int col) const;
37 
39  Matrix inverse () const;
40 
42  Matrix minorReduced (int rowOmit, int colOmit) const;
43 
45  Matrix operator* (const Matrix &other) const;
46 
48  QVector<double> operator* (const QVector<double> other) const;
49 
51  int rows () const;
52 
54  void set (int row, int col, double value);
55 
57  QString toString () const;
58 
60  Matrix transpose () const;
61 
62 private:
63  Matrix();
64 
65  void addRowToAnotherWithScaling (int rowFrom,
66  int rowTo,
67  double factor);
68  int fold2dIndexes (int row, int col) const;
69  void initialize (int rows,
70  int cols);
71  Matrix inverseCramersRule () const;
72  Matrix inverseGaussianElimination () const;
73  unsigned int leadingZeros (int row) const; // Number of leading zeros in the specified zero
74  void normalizeRow (int rowToNormalize,
75  int colToNormalize);
76  void switchRows (int row1,
77  int row2);
78 
79  int m_rows; // Height of matrix
80  int m_cols; // Width of matrix
81  QVector<double> m_vector;
82 };
83 
84 #endif // MATRIX_H
Matrix inverse() const
Return the inverse of this matrix.
Definition: Matrix.cpp:121
Matrix operator*(const Matrix &other) const
Multiplication operator with a matrix.
Definition: Matrix.cpp:327
Matrix transpose() const
Return the transpose of the current matrix.
Definition: Matrix.cpp:410
Matrix & operator=(const Matrix &matrix)
Assignment operator.
Definition: Matrix.cpp:34
Matrix minorReduced(int rowOmit, int colOmit) const
Return minor matrix which is the original with the specified row and column omitted. The name &#39;minor&#39; is a reserved word.
Definition: Matrix.cpp:289
double determinant() const
Return the determinant of this matrix.
Definition: Matrix.cpp:65
int cols() const
Width of matrix.
Definition: Matrix.cpp:60
Matrix class that supports arbitrary NxN size.
Definition: Matrix.h:14
int rows() const
Height of matrix.
Definition: Matrix.cpp:364
QString toString() const
Dump matrix to a string.
Definition: Matrix.cpp:386