⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matutil.htm

📁 This matrix C++ template class library is for performing common matrix operations in your C++ progra
💻 HTM
字号:
<html>
<head>
  <link rel=stylesheet href="styles.css" type="text/css">
  <title>Utility methods</title>
</head>
<body>

<h6 align=right>
<a href="matdcmp.htm">Prev</a> |
<a href="manual.htm">Up</a> |
<a href="eigen.htm">Next</a>
</h6>

<h2>Utility methods</h2>

<p>
The following utility methods are available for the matrix class.
</p>

<pre><code><a href="#m1">1</a>. size_t size () const;
<a href="#m2">2</a>. size_t typesize () const;

<a href="#m3">3</a>. size_t rowno () const;
<a href="#m4">4</a>. size_t colno () const;

<a href="#m5">5</a>. size_t colsize () const;
<a href="#m6">6</a>. size_t rowsize () const;

<a href="#m7">7</a>. T sum () const;
<a href="#m8">8</a>. T min () const;
<a href="#m9">9</a>. T max () const;
<a href="#m10">10</a>. T trace (int i=0) const;

<a href="#m11">11</a>. void resize (size_t nRow, size_t nCol);
<a href="#m12">12</a>. void free ();

<a href="#m13">13</a>. void null ();
<a href="#m14">14</a>. void unit ();
<a href="#m15">15</a>. void rand (unsigned RandMax = 1, unsigned RandSeed = 0);

<a href="#m16">16</a>. matrix&lt;T&gt; adj () const;
<a href="#m17">17</a>. T cofact (size_t row, size_t col) const;
<a href="#m18">18</a>. T det () const;
<a href="#m19">19</a>. T cond () const;
<a href="#m20">20</a>. size_t rank () const;

<a href="#m21">21</a>. T norm1 () const;
<a href="#m22">22</a>. T norm2 () const;
<a href="#m23">23</a>. T normI () const;
<a href="#m24">24</a>. T normF () const;

<a href="#m25">25</a>. matrix&lt;T&gt; apply (T (*fn)(T v)) const;
<a href="#m26">26</a>. matrix&lt;T&gt; apply (T (*fn)(const T&amp; v)) const;
<a href="#m27">27</a>. matrix&lt;T&gt; apply (T (*fn)(size_t i, size_t j, T v)) const;
<a href="#m28">28</a>. matrix&lt;T&gt; apply (T (*fn)(size_t i, size_t j, const T&amp; v)) const;

</code></pre>

<p>
<ol>
<li><a name="m1"></a>Returns the number of elements in a matrix object.</li><br><br>

<li><a name="m2"></a>Returns the type size of the matrix elements.</li><br><br>

<li><a name="m3"></a>Returns the row number of a matrix.</li><br><br>

<li><a name="m4"></a>Returns the column number of a matrix.</li><br><br>

<li><a name="m5"></a>Returns the number of elements in a column of a matrix, i.e., its row number.</li><br><br>

<li><a name="m6"></a>Returns the number of elements in a row of a matrix, i.e., its column number.</li><br><br>

<li><a name="m7"></a>Returns the sum of all elements of a matrix.</li><br><br>

<li><a name="m8"></a>Returns the minimum value of all matrix elements.</li><br><br>

<li><a name="m9"></a>Returns the maximum value of all matrix elements.</li><br><br>

<li><a name="m10"></a>Returns the sum of diagonal elements of a matrix. The default diagonal is the main diagonal of the matrix.</li><br><br>

<li><a name="m11"></a>Resizes a matrix to a <i>nRow</i> by <i>nCol</i> matrix. This is an expensive operation and should not be used frequently unless it is necessary.</li><br><br>

<li><a name="m12"></a>Frees the memory associated with a matrix object and sets its size as zero by zero matrix. Note that you can't use a zero size matrix in any operation.</li><br><br>

<li><a name="m13"></a>Sets all elements of a matrix equal to zero.</li><br><br>

<li><a name="m14"></a>Sets the matrix as a unit matrix, i.e., its main diagonal elements will be equal to 1.0 and the rest zero.</li><br><br>

<li><a name="m15"></a>Generates a random number matrix. By default the random number will be from 0 to 1, but you can provide the maximum value and initial seed value for the random number generator.</li><br><br>

<li><a name="m16"></a>Returns the adjoin of a matrix. This is an expensive operation and only of academic interest.</li><br><br>

<li><a name="m17"></a>Returns the cofactor of <i>i</i>th row and <i>j</i>th column of a matrix.</li><br><br>

<li><a name="m18"></a>Returns the determinant of a matrix.</li><br><br>

<li><a name="m19"></a>Returns the condition number of a matrix.</li><br><br>

<li><a name="m20"></a>Returns the rank of a matrix.</li><br><br>

<li><a name="m21"></a>Returns the one norm of a matrix.</li><br><br>

<li><a name="m22"></a>Returns the two norm of a matrix.</li><br><br>

<li><a name="m23"></a>Returns the infinity norm of a matrix.</li><br><br>

<li><a name="m24"></a>Returns the Frobenius norm of a matrix.</li><br><br>

<li><a name="m25"></a>Applies the function <i>fn</i> to all elements of a matrix and returns the new matrix object.</li><br><br>

<li><a name="m26"></a>Applies the function <i>fn</i> to all elements of a matrix and returns the new matrix object.</li><br><br>

<li><a name="m27"></a>Applies the function <i>fn</i> to all elements of a matrix and returns the new matrix object.</li><br><br>

<li><a name="m28"></a>Applies the function <i>fn</i> to all elements of a matrix and returns the new matrix object.</li><br><br>
</ol>
</p>

<h5>Examples</h5>

<pre><code>typedef matrix&lt;double&gt; Matrix;

Matrix A(6,4);
double x;
size_t i,j;

A.rand( 100);           // Generates a random matrix with elements 0 to 100

i = A.size();           // i = 6 x 4 = 24
j = A.rowno();          // Row number equal to 6
j = A.colno();          // Column number equal to 4

A.resize( 4, 4);        // Resize the matrix to a 4 x 4 one
x = A.sum();            // Sum of all elements
x = A.trace(-1);        // Sum of the diagonal elements just below the main diagonal

x = A.det();            // Determinant of A
x = A.cond();           // Condition number of A
x = A.normF();          // Frobenius norm of A

Matrix B = A.apply(sin);// Apply <i>sin</i> function to A
A.unit();               // A is now a unit matrix

</code></pre>

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -