26 #include "jama/jama_svd.h" 27 #include "jama/jama_eig.h" 28 #include "jama/jama_lu.h" 42 std::string m =
"Invalid matrix dimensions";
45 p_matrix = TNT::Array2D<double>(n, m, value);
52 p_matrix = matrix.copy();
63 std::string m =
"Invalid matrix dimensions";
67 for(
int i = 0; i < identity.Rows(); i++) {
77 if(Rows() != Columns()) {
78 std::string m =
"Unable to calculate the determinant, the matrix is not square.";
81 JAMA::LU<double> lu(p_matrix);
89 if(Rows() != Columns()) {
90 std::string m =
"Unable to calculate the trace, the matrix is not square.";
94 for(
int i = 0; i < Rows(); i++) {
95 trace += p_matrix[i][i];
104 if(Columns() != matrix.Rows()) {
105 std::string m =
"Incompatible matrix dimensions, cannot multiply the matrices.";
108 TNT::Array2D<double> m(matrix.Rows(), matrix.Columns());
109 for(
int i = 0; i < m.dim1(); i++) {
110 for(
int j = 0; j < m.dim2(); j++) {
111 m[i][j] = matrix[i][j];
114 return Matrix(TNT::matmult(p_matrix, m));
121 if(Rows() != matrix.Rows() || Columns() != matrix.Columns()) {
122 std::string m =
"Incompatible matrix dimensions, cannot add the matrices.";
125 TNT::Array2D<double> m(matrix.Rows(), matrix.Columns());
126 for(
int i = 0; i < m.dim1(); i++) {
127 for(
int j = 0; j < m.dim2(); j++) {
128 m[i][j] = matrix[i][j];
131 return Matrix(p_matrix + m);
138 if(Rows() != matrix.Rows() || Columns() != matrix.Columns()) {
139 std::string m =
"Incompatible matrix dimensions, cannot subtract the matrices.";
142 TNT::Array2D<double> m(matrix.Rows(), matrix.Columns());
143 for(
int i = 0; i < m.dim1(); i++) {
144 for(
int j = 0; j < m.dim2(); j++) {
145 m[i][j] = matrix[i][j];
149 return Matrix(p_matrix - m);
157 if(Rows() != matrix.Rows() || Columns() != matrix.Columns()) {
158 std::string m =
"Incompatible matrix dimensions, cannot multiply the matrices.";
161 TNT::Array2D<double> m(matrix.Rows(), matrix.Columns());
162 for(
int i = 0; i < m.dim1(); i++) {
163 for(
int j = 0; j < m.dim2(); j++) {
164 m[i][j] = matrix[i][j];
167 return Matrix(p_matrix * m);
174 Matrix product(Rows(), Columns());
175 for(
int i = 0; i < Rows(); i++) {
176 for(
int j = 0; j < Columns(); j++) {
177 product[i][j] = p_matrix[i][j] * scalar;
187 TNT::Array2D<double> transpose(p_matrix.dim2(), p_matrix.dim1());
188 for(
int i = 0; i < transpose.dim1(); i++) {
189 for(
int j = 0; j < transpose.dim2(); j++) {
190 transpose[i][j] = p_matrix[j][i];
200 if(Rows() != Columns()) {
201 std::string m =
"Unable to calculate the inverse, the matrix is not square.";
204 TNT::Array2D<double> id(p_matrix.dim1(), p_matrix.dim2(), 0.0);
205 for(
int i = 0; i < p_matrix.dim1(); i++)
id[i][i] = 1;
207 JAMA::LU<double> lu(p_matrix);
208 if(lu.det() == 0.0) {
209 std::string m =
"Cannot take the inverse of the matrix";
213 return Matrix(lu.solve(
id));
220 if(Rows() != Columns()) {
221 std::string m =
"Unable to calculate eigenvalues, the matrix is not square.";
224 JAMA::Eigenvalue<double>
E(p_matrix);
225 TNT::Array2D<double> D;
228 std::vector<double> eigenvalues(D.dim1());
229 for(
int i = 0; i < D.dim1(); i++) {
230 eigenvalues[i] = D[i][i];
241 if(Rows() != Columns()) {
242 std::string m =
"Unable to calculate eigenvectors, the matrix is not square.";
245 JAMA::Eigenvalue<double>
E(p_matrix);
246 TNT::Array2D<double> V;
256 for(
int i = 0; i < matrix.Rows(); i++) {
257 for(
int j = 0; j < matrix.Columns(); j++) {
259 if(j < matrix.Columns() - 1) os <<
" ";
261 if(i < matrix.Rows() - 1) os << endl;
Matrix Eigenvectors()
Compute the eigenvectors of the matrix and return them as columns of a matrix in ascending order...
Matrix Add(Matrix &matrix)
Add the two matrices.
Matrix(const int n, const int m, const double value=0.0)
Constructs an n x m Matrix containing the specified default value.
double Determinant()
Compute the determinant of the matrix.
This error is for when a programmer made an API call that was illegal.
Matrix Transpose()
Compute the transpose of the matrix.
Matrix Multiply(Matrix &matrix)
Multiply the two matrices.
double Trace()
Compute the determinant of the matrix.
#define _FILEINFO_
Macro for the filename and line number.
Matrix Inverse()
Compute the inverse of the matrix.
~Matrix()
Destroys the Matrix object.
Matrix Subtract(Matrix &matrix)
Subtract the input matrix from this matrix.
const double E
Sets some basic constants for use in ISIS programming.
std::vector< double > Eigenvalues()
Compute the eigenvalues of the matrix.
Matrix MultiplyElementWise(Matrix &matrix)
Multiply the two matrices element-wise (ie compute C such that C[i][j] = A[i][j]*B[i][j]) ...
Namespace for ISIS/Bullet specific routines.
static Matrix Identity(const int n)
Create an n x n identity matrix.
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.