Engauge Digitizer 2
Loading...
Searching...
No Matches
Matrix.h
Go to the documentation of this file.
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
18
20class Matrix
21{
22public:
24 Matrix(int N);
25
27 Matrix (int rows, int cols);
28
30 Matrix (const Matrix &other);
31
34
36 int cols () const;
37
39 double determinant () const;
40
42 double get (int row, int col) const;
43
48 Matrix inverse (int significantDigits,
50
52 Matrix minorReduced (int rowOmit, int colOmit) const;
53
55 Matrix operator* (const Matrix &other) const;
56
59
61 int rows () const;
62
64 void set (int row, int col, double value);
65
67 QString toString () const;
68
70 Matrix transpose () const;
71
72private:
73 Matrix();
74
75 void addRowToAnotherWithScaling (int rowFrom,
76 int rowTo,
77 double factor);
78 int fold2dIndexes (int row, int col) const;
79 void initialize (int rows,
80 int cols);
81 Matrix inverseCramersRule (MatrixConsistent &matrixConsistent,
82 double epsilonThreshold) const;
83 Matrix inverseGaussianElimination (int significantDigits,
85 unsigned int leadingZeros (int row) const; // Number of leading zeros in the specified zero
86 void normalizeRow (int rowToNormalize,
88 int significantDigits,
90 void switchRows (int row1,
91 int row2);
92
93 // Return true if value is sufficiently far from zero that we can divide by it as part of
94 // calculating a matrix inverse. The epsilon threshold is proportional to the largest value in the
95 // matrix since a good threshold of 1e-8 for matrix elements near 1 should be scaled to
96 // 1e-18 for matrix elements near 1e-10
97 bool valueFailsEpsilonTest (double value,
98 double epsilonThreshold) const;
99
100 int m_rows; // Height of matrix
101 int m_cols; // Width of matrix
102 QVector<double> m_vector;
103};
104
105#endif // MATRIX_H
const int INNER_RADIUS_MIN
MatrixConsistent
Indicates if matrix is consistent (i.e. has at least one solution)
Definition Matrix.h:14
@ MATRIX_CONSISTENT
Definition Matrix.h:15
@ MATRIX_INCONSISTENT
Definition Matrix.h:16
Matrix class that supports arbitrary NxN size.
Definition Matrix.h:21
double determinant() const
Return the determinant of this matrix.
Definition Matrix.cpp:66
int rows() const
Height of matrix.
Definition Matrix.cpp:423
Matrix & operator=(const Matrix &matrix)
Assignment operator.
Definition Matrix.cpp:35
Matrix inverse(int significantDigits, MatrixConsistent &matrixConsistent) const
Return the inverse of this matrix.
Definition Matrix.cpp:123
Matrix minorReduced(int rowOmit, int colOmit) const
Return minor matrix which is the original with the specified row and column omitted....
Definition Matrix.cpp:326
void set(int row, int col, double value)
Set (row, col) element.
Definition Matrix.cpp:428
Matrix transpose() const
Return the transpose of the current matrix.
Definition Matrix.cpp:469
Matrix operator*(const Matrix &other) const
Multiplication operator with a matrix.
Definition Matrix.cpp:386
double get(int row, int col) const
Return (row, col) element.
Definition Matrix.cpp:98
QString toString() const
Dump matrix to a string.
Definition Matrix.cpp:445
int cols() const
Width of matrix.
Definition Matrix.cpp:61