Skip to content
Snippets Groups Projects

Add trace function for squared TinyMatrix

11 files
+ 916
37
Compare changes
  • Side-by-side
  • Inline

Files

+ 37
7
@@ -2589,7 +2589,8 @@ The output is
#+RESULTS: dot-examples
A set of ~det~ functions is defined to get the determinant of matrices
$\mathbb{R}^{1\times1}$, $\mathbb{R}^{2\times2}$ and $\mathbb{R}^{3\times3}$.
of $\mathbb{R}^{1\times1}$, $\mathbb{R}^{2\times2}$ and
$\mathbb{R}^{3\times3}$.
#+NAME: det-examples
#+BEGIN_SRC pugs :exports both :results output
import math;
@@ -2601,20 +2602,47 @@ $\mathbb{R}^{1\times1}$, $\mathbb{R}^{2\times2}$ and $\mathbb{R}^{3\times3}$.
The output is
#+RESULTS: det-examples
The ~trace~ functions compute the trace of matrices of
$\mathbb{R}^{1\times1}$, $\mathbb{R}^{2\times2}$ and $\mathbb{R}^{3\times3}$.
#+NAME: trace-examples
#+BEGIN_SRC pugs :exports both :results output
import math;
cout << "trace([[1.2]]) = " << trace([[1.2]]) << "\n";
cout << "trace([[1,2],[3,4]]) = " << trace([[1,2],[3,4]]) << "\n";
cout << "trace([[1,2,3],[4,5,6],[7,8,9]]) = "
<< trace([[1,2,3],[4,5,6],[7,8,9]]) << "\n";
#+END_SRC
The output is
#+RESULTS: trace-examples
Also, one can compute inverses of $\mathbb{R}^{1\times1}$,
$\mathbb{R}^{2\times2}$ and $\mathbb{R}^{3\times3}$ matrices using the
~inverse~ function set.
#+NAME: inverse-examples
#+BEGIN_SRC pugs :exports both :results output
import math;
cout << "det([[1.2]]) = " << inverse([[1.2]]) << "\n";
cout << "det([[1,2],[3,4]]) = " << inverse([[1,2],[3,4]]) << "\n";
cout << "det([[3,2,1],[5,6,4],[7,8,9]]) = "
<< det([[3,2,1],[5,6,4],[7,8,9]]) << "\n";
cout << "inverse([[1.2]]) = " << inverse([[1.2]]) << "\n";
cout << "inverse([[1,2],[3,4]]) = " << inverse([[1,2],[3,4]]) << "\n";
cout << "inverse([[3,2,1],[5,6,4],[7,8,9]]) = "
<< inverse([[3,2,1],[5,6,4],[7,8,9]]) << "\n";
#+END_SRC
The output is
#+RESULTS: inverse-examples
Transpose of matrices of $\mathbb{R}^{1\times1}$,
$\mathbb{R}^{2\times2}$ and $\mathbb{R}^{3\times3}$ are obtained using the
~transpose~ functions.
#+NAME: transpose-examples
#+BEGIN_SRC pugs :exports both :results output
import math;
cout << "transpose([[1.2]]) = " << transpose([[1.2]]) << "\n";
cout << "transpose([[1,2],[3,4]]) = " << transpose([[1,2],[3,4]]) << "\n";
cout << "transpose([[3,2,1],[5,6,4],[7,8,9]]) = "
<< transpose([[3,2,1],[5,6,4],[7,8,9]]) << "\n";
#+END_SRC
The output is
#+RESULTS: transpose-examples
#+BEGIN_note
Observe that the use of a proper rounding or truncation function is
the right way to convert a real value to an integer one. Available
@@ -3246,18 +3274,20 @@ Here is the list of these functions
- ~tan: Vh -> Vh~
- ~tanh: Vh -> Vh~
The ~det~ functions are defined for $\mathbb{P}_0(\mathbb{R^{}}^{1\times1})$,
A few functions are defined for $\mathbb{P}_0(\mathbb{R^{}}^{1\times1})$,
$\mathbb{P}_0(\mathbb{R^{}}^{2\times2})$ and
$\mathbb{P}_0(\mathbb{R^{}}^{3\times3})$ data and the return value is a
$\mathbb{P}_0(\mathbb{R})$ function. The value is simply the
application of the function to the cell values.
- ~det: Vh -> Vh~
- ~trace: Vh -> Vh~
The ~inverse~ functions are defined for $\mathbb{P}_0(\mathbb{R}^{d\times d})$
Also, functions are defined for $\mathbb{P}_0(\mathbb{R}^{d\times d})$
data and the return value is a $\mathbb{P}_0(\mathbb{R}^{d\times d})$
function, with $d\in\{1,2,3\}$. The value is simply the application of
the function to the cell values.
- ~inverse: Vh -> Vh~
- ~transpose: Vh -> Vh~
****** ~Vh*Vh -> Vh~
Loading