📄 matrix.h
字号:
*/
bool InsertSubMatrix( const Matrix &src, const unsigned dst_row, const unsigned dst_col );
/**
\brief Zero the entire matrix.
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Zero(); // Set A back to zeros.
result = A.PrintStdout(); // Print Matrix A. A = [0 0 0; 0 0 0; 0 0 0].
\endcode
\return true if successful, false otherwise.
*/
bool Zero();
/**
\brief Zero all elements in a specified column.
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.ZeroColumn(1); // Set the second column of A back to zeros.
result = A.PrintStdout(); // Print Matrix A. A = [1 0 3; 4 0 6; 7 0 9].
\endcode
\return true if successful, false otherwise.
*/
bool ZeroColumn( const unsigned col );
/**
\brief Zero all elements in a specified row.
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.ZeroRow(1); // Set the second row of A back to zeros.
result = A.PrintStdout(); // Print Matrix A. A = [1 2 3; 0 0 0; 7 8 9].
\endcode
\return true if successful, false otherwise.
*/
bool ZeroRow( const unsigned row );
/**
\brief Fill the matrix with the given value.
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Fill(7); // Fill the matrix with 7.0.
result = A.PrintStdout(); // Print Matrix A. A = [7 7 7; 7 7 7; 7 7 7].
\endcode
\return true if successful, false otherwise.
*/
bool Fill( const double value );
/**
\brief Fill the matrix column with the given value.
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.FillColumn(1,7); // Fill the second column with 7.0.
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = [1 7 3; 4 7 6; 7 7 9].
\endcode
\return true if successful, false otherwise.
*/
bool FillColumn( const unsigned col, const double value );
/**
\brief Fills the matrix row with the given value.
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.FillRow(1,7); // Fill the second row with 7.0.
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = [1 2 3; 7 7 7; 7 8 9].
\endcode
\return true if successful, false otherwise.
*/
bool FillRow( const unsigned row, const double value );
/**
\brief Reverse the order of elements of a column.
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.FlipColumn(1); // Flip the second column.
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = [1 8 3; 4 5 6; 7 2 9].
\endcode
\return true if successful, false otherwise.
*/
bool FlipColumn( const unsigned col );
/**
\brief Reverse the order of elements of a row.
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.FlipRow(1); // Flip the second row.
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = [1 2 3; 6 5 4; 7 8 9].
\endcode
\return true if successful, false otherwise.
*/
bool FlipRow( const unsigned row );
/**
\brief Set the matrix to identity using the current dimensions.
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Identity(); // Set A to identity.
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = [1 0 0; 0 1 0; 0 0 1].
\endcode
\return true if successful, false otherwise.
*/
bool Identity();
/**
\brief Set the matrix to identity using the specified dimension (nxn).
\code
Matrix A;
bool result;
result = A.Identity(3); // Set A to identity, 3x3.
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = [1 0 0; 0 1 0; 0 0 1].
\endcode
\return true if successful, false otherwise.
*/
bool Identity(const unsigned dimension);
public: // Inplace Operations
/**
\brief Transpose the matrix as an inplace operation.
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Inplace_Transpose(); // Make A = transpose(A).
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = [1 4 7; 2 5 8; 3 6 9].
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_Transpose();
bool Inplace_transpose() { return this->Inplace_Transpose(); }
/**
\brief Round the matrix elements to the specified presision. \n
e.g. precision = 0 1.8 -> 2 (default)\n
e.g. precision = 1, 1.45 -> 1.5 \n
e.g. precision = 2 1.456 -> 1.46 \n
e.g. precision = 3, 1.4566 -> 1.457 \n
*
\code
Matrix A;
A = "[1.09 2.08 3.07; 4.06 5.05 6.04; 7.03 8.02 9.01]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Inplace_Round(1); // Make A = round(A) to the 1st decimal place.
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = "[1.1 2.1 3.1; 4.1 5.1 6.0; 7.0 8.0 9.0]";
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_Round( const unsigned precision = 0 );
bool Inplace_round( const unsigned precision = 0 ) { return this->Inplace_Round( precision ); }
/**
\brief Round the matrix elements to the nearest integers towards minus infinity.
\code
Matrix A;
A = "[1.9 2.8 3.7; -4.6 -5.5 -6.4; 7.3 8.2 9.1]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Inplace_Floor(); // Make A = floor(A).
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = "[1 2 3; -5 -6 -7; 7 8 9]";
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_Floor();
bool Inplace_floor() { return this->Inplace_Floor(); }
/**
\brief Round the matrix elements to the nearest integers towards infinity.
\code
Matrix A;
A = "[1.9 2.8 3.7; -4.6 -5.5 -6.4; 7.3 8.2 9.1]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Inplace_Ceil(); // Make A = ceil(A).
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = "[2 3 4; -4 -5 -6; 8 9 10]";
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_Ceil();
bool Inplace_ceil() { return this->Inplace_Ceil(); }
/**
\brief Rounds the matrix elements of X to the nearest integers towards zero.
\code
Matrix A;
A = "[1.9 2.8 3.7; -4.6 -5.5 -6.4; 7.3 8.2 9.1]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Inplace_Fix(); // Make A = fix(A).
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = "[1 2 3; -4 -5 -6; 7 8 9]";
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_Fix();
/** \brief Add a scaler double (ie: M += 5).
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Inplace_AddScalar(1); // A += 1.
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = "[2 3 4; 5 6 7; 8 9 10]";
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_AddScalar( const double scalar );
/**
\brief Subtract a scaler double (ie: M -= 5).
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Inplace_SubtractScalar(1); // A -= 1.
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = "[0 1 2; 3 4 5; 6 7 8]";
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_SubtractScalar( const double scalar );
/**
\brief Multiply by scaler double (ie: M *= 5).
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Inplace_MultiplyScalar(5); // A *= 5.
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = "[5 10 15; 20 25 30; 35 40 45]";
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_MultiplyScalar( const double scalar );
/**
\brief Divide by scaler double (ie: M /= 5).
\code
Matrix A;
A = "[5 10 15; 20 25 30; 35 40 45]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Inplace_DivideScalar(5); // A /= 5.
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = "[1 2 3; 4 5 6; 7 8 9]";
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_DivideScalar( const double scalar );
/**
\brief Raise the matrix to a power scaler double (ie: M ^= 5).
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
result = A.Inplace_PowerScalar(2); // A = A.^2. Not A*A! Each element is raised.
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = "[1 4 9; 16 25 36; 49 64 81]";
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_PowerScalar( const double scalar );
/**
\brief Add a scaler double (ie: M += (4+2i)).
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
std::complex<double> cplx(4.0,2.0);
result = A.Inplace_AddScalarComplex(cplx); // A += (4+2i).
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = "[5+2i 6+2i 7+2i; 8+2i 9+2i 10+2i; 11+2i 12+2i 13+2i]";
cout << "A(0,0) = " << A(0,0).real() << "+" << A(0,0).imag() << "i " << endl;
\endcode
* \return true if successful, false otherwise.
*/
bool Inplace_AddScalarComplex( const std::complex<double> cplx );
/**
\brief Subtract a scaler double (ie: M -= (5+2i)).
\code
Matrix A;
A = "[1 2 3; 4 5 6; 7 8 9]";
bool result;
result = A.PrintStdout(); // Print Matrix A.
std::complex<double> cplx(5.0,2.0);
result = A.Inplace_SubtractScalarComplex(cplx); // A -= (5+2i).
cout << endl;
result = A.PrintStdout(); // Print Matrix A. A = "[-4-2i -3-2i -2-2i; -1-2i 0-2i 1-2i; 2-2i 3-2i 4-2i]";
cout << "A(0,0) = " << A(0,0).real() << "+" << A(0,0).imag() << "i " << endl;
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_SubtractScalarComplex( const std::complex<double> cplx );
/**
\brief Multiply by scaler double (ie: M *= (5+2i)).
\code
Matrix M;
M = "[10 20]";
std::complex<double> cplx(5,2);
if( !M.Inplace_MultiplyScalarComplex(cplx) )
return false;
// M
// 50+20i 100+40i
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_MultiplyScalarComplex( const std::complex<double> cplx );
/**
\brief Divide by scaler double (ie: M /= (5+1i)).
\code
Matrix M;
M = "[10+2i 20+4i]";
std::complex<double> cplx(5,1);
if( !M.Inplace_DivideScalarComplex(cplx) )
return false;
// M
// 2 4
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_DivideScalarComplex( const std::complex<double> cplx );
/**
\brief Raise the matrix to a power scaler double (ie: M ^= (5+2i)).
\code
Matrix M;
M = "[2 3]";
std::complex<double> cplx(5,2);
if( !M.Inplace_PowerScalarComplex(cplx) )
return false;
// M
// 5.87062319178566+31.4568876931598i -142.459949032798+196.860770397691i
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_PowerScalarComplex( const std::complex<double> cplx );
/**
\brief Compute the absolute value of each element in the matrix.
\code
Matrix A;
A = "[-1 -2; -3 -4]";
if( !A.Inplace_Abs() )
return false;
// A
// 1 2
// 3 4
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_Abs();
/**
\brief Compute the value^2 of each element in the matrix.
\code
Matrix A;
A = "[1 2; -3 -4]";
if( !A.Inplace_Sqr() )
return false;
// A
// 1 4
// 9 16
\endcode
\return true if successful, false otherwise.
*/
bool Inplace_Sqr();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -