Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Matrix
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
14
enum
MatrixConsistent
{
15
MATRIX_CONSISTENT
,
16
MATRIX_INCONSISTENT
17
};
18
20
class
Matrix
21
{
22
public
:
24
Matrix
(
int
N);
25
27
Matrix
(
int
rows
,
int
cols
);
28
30
Matrix
(
const
Matrix
&other);
31
33
Matrix
&
operator=
(
const
Matrix
&matrix);
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,
49
MatrixConsistent
&matrixConsistent)
const
;
50
52
Matrix
minorReduced
(
int
rowOmit,
int
colOmit)
const
;
53
55
Matrix
operator*
(
const
Matrix
&other)
const
;
56
58
QVector<double>
operator*
(
const
QVector<double> other)
const
;
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
72
private
:
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,
84
MatrixConsistent
&matrixConsistent)
const
;
85
unsigned
int
leadingZeros (
int
row)
const
;
// Number of leading zeros in the specified zero
86
void
normalizeRow (
int
rowToNormalize,
87
int
colToNormalize,
88
int
significantDigits,
89
MatrixConsistent
&matrixConsistent);
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
MatrixConsistent
MatrixConsistent
Indicates if matrix is consistent (i.e. has at least one solution).
Definition
Matrix.h:14
MATRIX_CONSISTENT
@ MATRIX_CONSISTENT
Definition
Matrix.h:15
MATRIX_INCONSISTENT
@ MATRIX_INCONSISTENT
Definition
Matrix.h:16
Matrix::determinant
double determinant() const
Return the determinant of this matrix.
Definition
Matrix.cpp:66
Matrix::rows
int rows() const
Height of matrix.
Definition
Matrix.cpp:423
Matrix::operator=
Matrix & operator=(const Matrix &matrix)
Assignment operator.
Definition
Matrix.cpp:35
Matrix::inverse
Matrix inverse(int significantDigits, MatrixConsistent &matrixConsistent) const
Return the inverse of this matrix.
Definition
Matrix.cpp:123
Matrix::minorReduced
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
Matrix::set
void set(int row, int col, double value)
Set (row, col) element.
Definition
Matrix.cpp:428
Matrix::transpose
Matrix transpose() const
Return the transpose of the current matrix.
Definition
Matrix.cpp:469
Matrix::Matrix
Matrix(int N)
Simple constructor of square matrix with initialization to identity matrix.
Definition
Matrix.cpp:12
Matrix::operator*
Matrix operator*(const Matrix &other) const
Multiplication operator with a matrix.
Definition
Matrix.cpp:386
Matrix::get
double get(int row, int col) const
Return (row, col) element.
Definition
Matrix.cpp:98
Matrix::toString
QString toString() const
Dump matrix to a string.
Definition
Matrix.cpp:445
Matrix::cols
int cols() const
Width of matrix.
Definition
Matrix.cpp:61
Generated on
for Engauge Digitizer by
1.17.0