\newpage\section{Class \Iclass{matrix}} % (fold) \label{sec:matrices} The \code{matrix} class is currently experimental, and its attribute and method names have not yet been finalized, indicating that this class is still evolving. Certain connections have been made with other classes, such as the \code{point} class. Additionally, a new attribute, \code{mtx}, has been included, associating a column matrix with the point, where the elements correspond to the point's coordinates in the original base. Similarly, an attribute has been added to the \code{vector} class, where \code{mtx} represents a column matrix consisting of the two affixes that compose the vector. This \code{matrix} class has been created to avoid the need for an external library, and has been adapted to plane transformations. It allows you to use complex numbers. \lefthand\ To display matrices, you'll need to load the \pkg{amsmath} package. {\color{red}\lefthand\ } While some methods are valid for any matrix size, the majority are reserved for square matrices of order 2 and 3. \subsection{Matrix creation} % (fold) \label{sub:matrix_creation} \begin{itemize} \item The first method is: (Refer to \ref{ssub:method_new}) \begin{minipage}{.5\textwidth} \begin{mybox} |M = matrix: new ({{a,b},{c,d}}) | \\ or |M = matrix: new {{a,b},{c,d}} | \\ a, b, c, et d being real or complex numbers. \end{mybox} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} M = matrix: new {{a,b},{c,d}} tex.print('M = ') M : print () \end{tkzelements} \end{minipage} \item It is also possible to obtain a square matrix with: (Refer to \ref{ssub:method_square}) \begin{mybox} |M = matrix : square (2,a,b,c,d)| \end{mybox} \item In the case of a column vector: (Refer to \ref{ssub:method_vector}) \begin{minipage}{.5\textwidth} \begin{mybox} |V = matrix : vector (1,2,3)| \end{mybox} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} V = matrix : vector (1,2,3) tex.print('V = ') V : print () \end{tkzelements} \end{minipage} \item Homogeneous transformation matrix (Refer to \ref{ssub:method_htm}) The objective is to generate a matrix with homogeneous coordinates capable of transforming a coordinate system through rotation, translation, and scaling. To achieve this, it is necessary to define both the rotation angle, the coordinates of the new origin ans the scaling factors. \begin{minipage}{.5\textwidth} \begin{mybox} |H = matrix : htm (math.pi/3,1,2,2,1)| \end{mybox} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} H = matrix : htm (math.pi/3,1,2,2,1) tex.print('H = ') H: print () \end{tkzelements} \end{minipage} \end{itemize} % subsection matrix_creation (end) \subsection{Display a matrix: method \code{print}} % (fold) \label{sub:display_a_matrix_method_print} This method (Refer to \ref{ssub:method_print}) is necessary to control the results, so here are a few explanations on how to use it. It can be used on real or complex matrices, square or not. A few options allow you to format the results. You need to load the \pkg{amsmath} package to use the "print" method. Without this package, it is possible to display the contents of the matrix without formatting with |print_array (M)| \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} M = matrix : new {{1,-1},{2,0}} M : print () \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} M = matrix : new {{1,-1},{2,0}} M : print () \end{tkzelements} \end{minipage} % subsection display_a_matrix_method_print (end) \subsection{Attibutes of a matrix} % (fold) \label{sub:attibutes_of_a_matrix} \bgroup \catcode`_=12 \small \captionof{table}{Matrix attributes.}\label{matrix:att} \begin{tabular}{lll} \toprule \textbf{Attributes} & \textbf{Application} &\\ \Iattr{matrix}{set} & |M.set = {{a,b},{c,d}}| & table of tables\\ \Iattr{matrix}{rows} & |M.rows| & number of rows\\ \Iattr{matrix}{cols} & |M.cols| & number of columns\\ \Iattr{matrix}{type} & |M.type = "matrix"| & the type of object \\ \Iattr{matrix}{det} & |M.det| & determinant of a square matrix or |nil|\\ \bottomrule % \end{tabular} \egroup \subsubsection{Attribute \code{set}} % (fold) \label{sub:attribute_set} A simple array such as |{{1,2},{2,-1}}| is often considered a "matrix". In "tkz-elements", we'll consider |M| defined by |matrix : new ({{1,1},{0,2}})| as a matrix and |M.set| as an array (|M.set = {{1,1},{0,2}}|). You can access a particular element of the matrix, for example: |M.set[2][1]| gives \tkzUseLua{M.set[2][2]}. |\tkzUseLua{M.set[2][1]}| is the expression that displays $2$. The number of rows is accessed with |M.rows| and the number of columns with |M.cols|, here's an example: \vspace{.5em} \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} M = matrix : new ({{1,2,3},{4,5,6}}) M : print () tex.print("Rows: "..M.rows) tex.print("Cols: "..M.cols) \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} M = matrix : new ({{1,2,3},{4,5,6}}) M : print () tex.print("Rows: "..M.rows) tex.print("Cols: "..M.cols) \end{tkzelements} \end{minipage} % subsubsection attribute_set (end) \subsubsection{Determinant with real numbers} % (fold) \label{ssub:determinant_matrix} The matrix must be square. This library was created for matrices of dimension 2 or 3, but it is possible to work with larger sizes. |det| is an attribute of the "matrix" object, but the determinant can also be obtained with the function |determinant(M)|. \vspace{.5em} \begin{minipage}{.6\textwidth} \begin{Verbatim} \begin{tkzelements} M = matrix : square (3,1,1,0,2,-1,-2,1,-1,2) M : print () tex.print ('\\\\') tex.print ("Its determinant is: " .. M.det) \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.4\textwidth} \begin{tkzelements} M = matrix : square (3,1,1,0,2,-1,-2,1,-1,2) M : print () tex.print ('\\\\') tex.print ("Its determinant is: "..M.det) \end{tkzelements} \end{minipage} % subsubsection determinant (end) \subsubsection{Determinant with complex numbers} % (fold) \label{ssub:determinant_with_complex_numbers} \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} a = point :new (1,-2) b = point :new (0,1) c = point :new (1,1) d = point :new (1,-1) A = matrix : new ({{a, b}, {c,d}}) tex.print(tostring(A.det)) \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} a = point :new (1,-2) b = point :new (0,1) c = point :new (1,1) d = point :new (1,-1) A = matrix : new ({{a, b}, {c,d}}) tex.print(tostring(A.det)) \end{tkzelements} \end{minipage} % subsubsection determinant_with_complex_numbers (end) % subsection attibutes_of_a_matrix (end) \subsection{Metamethods for the matrices} % (fold) \label{sub:metamethods_for_the_matrices} Conditions on matrices must be valid for certain operations to be possible. \bgroup \catcode`_=12 \small \begin{minipage}{\textwidth} \captionof{table}{Matrix metamethods.}\label{matrix:meta} \begin{tabular}{lll} \toprule \textbf{Metamethods} & \textbf{Application} \\ \midrule \_\_\Immeth{matrix}{add(M1,M2)} & |M1 + M2| & \\ \_\_\Immeth{matrix}{sub(M1,M2)} & |M1 - M2| & \\ \_\_\Immeth{matrix}{unm(M} & |- M| & \\ \_\_\Immeth{matrix}{mul(M1,M2)} & |M1 * M2| & \\ \_\_\Immeth{matrix}{pow(M,n)} & |M ^ n| & n integer > or < 0 or |'T'|\\ \_\_\Immeth{matrix}{tostroing(M,n)} & tex.print(tostring(M)) & displays the matrix \\ \_\_\Immeth{matrix}{eq(M1,M2)} & true or false & \\ \bottomrule \end{tabular} \end{minipage} \egroup \subsubsection{Addition and subtraction of matrices} % (fold) \label{ssub:addition_of_matrices} To simplify the entries, I've used a few functions to simplify the displays. \vspace{.5em} \begin{minipage}{.6\textwidth} \begin{Verbatim} \begin{tkzelements} A = matrix : new ({{1,2},{2,-1}}) B = matrix : new ({{-1,0},{1,3}}) S = A + B D = A - B dsp(A,'A') nl() nl() dsp(B,'B') nl() nl() dsp(S,'S') sym(" = ") dsp(A) sym(' + ') dsp(B) nl() nl() dsp(D,'D') sym(" = ") dsp(A) sym(' - ') dsp(B) \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.4\textwidth} \begin{tkzelements} local function dsp (M,name) if name then tex.print(name..' = ')print_matrix(M) else print_matrix(M) end end local function sym (s) tex.print(' '..s..' ') end local function nl () tex.print('\\\\') end A = matrix : new ({{1,2},{2,-1}}) B = matrix : new ({{-1,0},{1,3}}) S = A + B D = A - B dsp(A,'A') nl() nl() dsp(B,'B') nl() nl() dsp(S,'S') sym(" = ") dsp(A) sym(' + ') dsp(B) nl() nl() dsp(D,'D') sym(" = ") dsp(A) sym(' - ') dsp(B) \end{tkzelements} \end{minipage} % subsubsection addition_of_matrices (end) \subsubsection{Multiplication and power of matrices} % (fold) \label{ssub:multiplication_of_matrices} To simplify the entries, I've used a few functions. You can find their definitions in the sources section of this documentation. \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} A = matrix : new ({{1,2},{2,-1}}) B = matrix : new ({{-1,0},{1,3}}) P = A * B I = A^-1 C = A^3 K = 2 * A T = A^'T' \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} local function dsp (M,name) if name then tex.print(name..' = ')print_matrix(M) else print_matrix(M) end end local function sym (s) tex.print(' '..s..' ') end local function nl () tex.print('\\\\') end A = matrix : new ({{1,2},{2,-1}}) B = matrix : new ({{-1,0},{1,3}}) P = A * B I = A ^-1 C = A ^3 K = 2 * A dsp(P,'P') sym(" = ") dsp(A) sym(' * ') dsp(B) nl() nl() dsp(A^-1,'$A^{-1}$') nl() nl() dsp(K,'K') nl() nl() dsp(A^('T'),"$A^{T}$") nl() nl() \end{tkzelements} \end{minipage} \subsubsection{Metamethod \code{eq}} % (fold) \label{ssub:metamthod_eq} Test whether two matrices are equal or identical. % subsubsection metamthod_eq (end) % subsubsection multiplication_of_matrices (end) % subsection metamethods_for_the_matrices (end) \subsection{Methods of the class matrix} % (fold) \label{sub:methods_of_the_class_matrix} \bgroup \catcode`_=12 \small \captionof{table}{Matrix methods.}\label{matrix:met} \begin{tabular}{lll} \toprule \textbf{Functions} & \textbf{Comments} & \\ \midrule \Igfct{matrix}{new(...)} & |M = matrix : new ({{1,2},{2,-1}})| & \\ \Igfct{matrix}{square()} & |M = matrix : square (2,1,2,2,-1)| & \\ \Igfct{matrix}{vector()} & |M = matrix : vector (2,1)| & \\ \Igfct{matrix}{htm()} & |M = matrix : htm (2,1,2,2,-1)| & \\ \midrule \textbf{Methods} & \textbf{Comments} & \\ \midrule \Imeth{matrix}{print(s,n)} & |M : print ()| & s='matrix' or ... default 'bmatrix' \\ \Imeth{matrix}{htm\_apply(...)} & |M : htm_apply (...)| & \\ \Imeth{matrix}{get()} & |M : get (i,j)| & i = raws , j = cols Refer to \ref{ssub:get_an_element_of_a_matrix} \\ \Imeth{matrix}{inverse()} & |M : inverse ()| & \\ \Imeth{matrix}{adjugate()} & |M : adjugate ()| & \\ \Imeth{matrix}{transpose()} & |M : transpose ()| & \\ \Imeth{matrix}{is\_diagonal()} & |true or false| & result :boolean \\ \Imeth{matrix}{is\_orthogonal()} & |true or false| & \\ \Imeth{matrix}{homogenization()} & |M : homogenization ()| & \\ \bottomrule \end{tabular} \egroup \subsubsection{Function \code{new}} % (fold) \label{ssub:method_new} This is the main method for creating a matrix. Here's an example of a 2x3 matrix with complex coefficients: \vspace{.5em} \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} a = point : new (1,0) b = point : new (1,1) c = point : new (-1,1) d = point : new (0,1) e = point : new (1,-1) f = point : new (0,-1) M = matrix : new ({{a,b,c},{d,e,f}}) M : print () \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} a = point : new (1,0) b = point : new (1,1) c = point : new (-1,1) d = point : new (0,1) e = point : new (1,-1) f = point : new (0,-1) M = matrix : new ({{a,b,c},{d,e,f}}) M : print () \end{tkzelements} \end{minipage} % subsubsection method_new (end) \subsubsection{Function \code{vector}} % (fold) \label{ssub:method_vector} The special case of a column matrix, frequently used to represent a vector, can be treated as follows: \vspace{.5em} \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} M = matrix : vector (1,2,3) M : print () \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} M = matrix : vector (1,2,3) M : print () \end{tkzelements} \end{minipage} % subsubsection method_vector (end) \subsubsection{Method \code{homogenization}} % (fold) \label{ssub:method_homogenization} \code{homogenization} of vector: the aim is to be able to use a homogeneous transformation matrix Let's take a point $A$ such that |z.A = point : new (2,-1)|. In order to apply a \code{htm} matrix, we need to perform a few operations on this point. The first is to determine the vector (matrix) associated with the point. This is straightforward, since there's a point attribute called \code{mtx} which gives this vector: \begin{mybox} z.A = point : new (2,-1)\\ V = z.A.mtx : homogenization () \end{mybox} which gives: \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} pi = math.pi M = matrix : htm (pi/4 , 3 , 1) z.A = point : new (2,-1) V = z.A.mtx : homogenization () z.A.mtx : print () tex.print ('then after homogenization: ') V : print () \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} pi = math.pi M = matrix : htm (pi/4 , 3 , 1) z.A = point : new (2,-1) V = z.A.mtx : homogenization () z.A.mtx : print () tex.print ('then after homogenization: ') V : print () \end{tkzelements} \end{minipage} % subsubsection method_homogenization (end) \subsubsection{Function \code{htm}: homogeneous transformation matrix} % (fold) \label{ssub:method_htm} There are several ways of using this transformation. First, we need to create a matrix that can associate a rotation with a translation. The main method is to create the matrix: \begin{mybox} pi = math.pi\\ M = matrix : htm (pi/4 , 3 , 1) \end{mybox} A 3x3 matrix is created which combines a $\pi/4$ rotation and a $\overrightarrow{t}=(3,1)$ translation. \begin{tkzelements} pi = math.pi M = matrix : htm (pi/4 , 3 , 1) M : print () \end{tkzelements} Now we can apply the matrix M. Let $A$ be the point defined here: \ref{ssub:method_homogenization}. By homogenization, we obtain the column matrix $V$. \begin{mybox} W = A * V \end{mybox} \begin{tkzelements} pi = math.pi M = matrix : htm (pi/4 , 3 , 1) M :print () z.A = point : new (2,-1) V = z.A.mtx : homogenization () V : print () tex.print('=') W = M * V W : print () \end{tkzelements} All that remains is to extract the coordinates of the new point. % subsubsection method_htm (end) \subsubsection{Method \code {get\_htm\_point}} % (fold) \label{ssub:method_code_get__htm__point} In the previous section, we obtained the $W$ matrix. Now we need to obtain the point it defines. The method \code{get\_htm\_point} extracts a point from a vector obtained after applying a \code{htm} matrix. \begin{minipage}{.5\textwidth} \begin{verbatim} \begin{tkzelements} W : print () z.P = get_htm_point(W) tex.print("The affix of $P$ is: ") tex.print(display(z.P)) \end{tkzelements} \end{verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} W : print () z.P = get_htm_point(W) tex.print("The affix of $P$ is: ") tex.print(display(z.P)) \end{tkzelements} \end{minipage} % subsubsection method_code_get__htm__point (end) \subsubsection{Method \code{htm\_apply}} % (fold) \label{ssub:method_code_htm__apply} The above operations can be simplified by using the \code{htm\_apply} method directly at point $A$. \begin{mybox} |z.Ap = M: htm_apply (z.A)|\\ % display (z.Ap) \end{mybox} Then the method \code{htm\_apply} transforms a point, a list of points or an object. \begin{tkzelements} pi = math.pi M = matrix : htm (pi/4 , 3 , 1 ) z.O = point : new (0,0) V.ori = z.O.mtx : homogenization () z.I = point : new (1,0) z.J = point : new (0,1) z.A = point: new (2,0) z.B = point: new (1,2) L.AB = line : new (z.A,z.B) z.Op,z.Ip,z.Jp = M : htm_apply (z.O,z.I,z.J) L.ApBp = M : htm_apply (L.AB) z.Ap = L.ApBp.pa z.Bp = L.ApBp.pb z.K = point : new (2,2) T = triangle : new ( z.I , z.J , z.K ) Tp = M : htm_apply (T) z.Kp = Tp.pc \end{tkzelements} \begin{minipage}{.6\textwidth} \begin{Verbatim} \begin{tkzelements} pi = math.pi M = matrix : htm (pi/4 , 3 , 1 ) z.O = point : new (0,0) V.ori = z.O.mtx : homogenization () z.I = point : new (1,0) z.J = point : new (0,1) z.A = point: new (2,0) z.B = point: new (1,2) L.AB = line : new (z.A,z.B) z.Op,z.Ip,z.Jp = M : htm_apply (z.O,z.I,z.J) L.ApBp = M : htm_apply (L.AB) z.Ap = L.ApBp.pa z.Bp = L.ApBp.pb z.K = point : new (2,2) T = triangle : new ( z.I , z.J , z.K ) Tp = M : htm_apply (T) z.Kp = Tp.pc \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.4\textwidth} \begin{tikzpicture}[gridded] \tkzGetNodes \tkzDrawPoints(O,O',A,B,A',B',K,K') \tkzLabelPoints(O,O',A,B,A',B',I,J,I',J',K,K') \tkzDrawSegments[->](O,I O,J O',I' O',J') \tkzDrawLines (A,B A',B') \tkzDrawPolygons[red](I,J,K I',J',K') \end{tikzpicture} \end{minipage} \vspace{.5 em} New cartesian coordinates system: \vspace{.5 em} \begin{minipage}{.5\textwidth} \begin{verbatim} \begin{tkzelements} pi = math.pi tp = tex.print nl = '\\\\' a = point(1,0) b = point(0,1) R = matrix : htm (pi/5,2,1) R : print () tp(nl) v = matrix : vector (1,2) v : print () v.h = v : homogenization () v.h : print () tp(nl) V = R * v.h V : print () z.N = get_htm_point(V) tex.print(display(z.N)) \end{tkzelements} \end{verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} pi = math.pi tp = tex.print nl = '\\\\' a = point(1,0) b = point(0,1) R = matrix : htm (pi/5,2,1) R : print () tp(nl) v = matrix : vector (1,2) v : print () v.h = v : homogenization () v.h : print () tp(nl) V = R * v.h V : print () z.N = get_htm_point(V) tex.print(display(z.N)) \end{tkzelements} \end{minipage} % subsubsection method_code_htm__apply (end) \subsubsection{Function \code{square}} % (fold) \label{ssub:method_square} We have already seen this method in the presentation of matrices. We first need to give the order of the matrix, then the coefficients, row by row. \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} M = matrix : square (2,2,3,-5,4) M : print () \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} M = matrix : square (2,2,3,-5,4) M : print () tex.print(S) \end{tkzelements} \end{minipage} % subsubsection method_square (end) \subsubsection{Method \Imeth{matrix}{print}} % (fold) \label{ssub:method_print} With the \pkg{amsmath} package loaded, this method can be used. By default, the \code{bmatrix} environment is selected, although you can choose from \code{matrix}, \code{pmatrix}, \code{Bmatrix}, "vmatrix", "Vmatrix". Another option lets you set the number of digits after the decimal point. The "tkz\_dc" global variable is used to set the number of decimal places. Here's an example: \vspace{.5em} \begin{Verbatim} \begin{tkzelements} M = matrix : new ({{math.sqrt(2),math.sqrt(3)},{math.sqrt(4),math.sqrt(5)}}) M : print ('pmatrix') \end{tkzelements} \end{Verbatim} \begin{tkzelements} M = matrix : new ({{math.sqrt(2),math.sqrt(3)},{math.sqrt(4),math.sqrt(5)}}) tkz_dc = 3 M : print ('pmatrix') \end{tkzelements} \vspace{.5em} You can also display the matrix as a simple array using the |print_array (M)| function. refer to the next example. In the case of a square matrix, it is possible to transmit a list of values whose first element is the order of the matrix. \vspace{.5em} \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} M = matrix : square (2,1,0,0,2) M : print () \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} M = matrix : square (2,1,0,0,2) M : print () \end{tkzelements} \end{minipage} % subsubsection method_print (end) \subsubsection{Display a table or array: function \code{print\_array}} % (fold) \label{ssub:display_a_table_or_array_function_code_print_array} We'll need to display results, so let's look at the different ways of displaying them, and distinguish the differences between arrays and matrices. Below, $A$ is an array. It can be displayed as a simple array or as a matrix, but we can't use the attributes and |A : print ()| is not possible because $A$ is not an object of the class \code{matrix}. If you want to display an array like a matrix you can use the function |print_matrix| (refer to the next example). \vspace{.5em} \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} A = {{1,2},{1,-1}} tex.print ('A = ') print_array (A) tex.print (' or ') print_matrix (A) M = matrix : new ({{1,1},{0,2}}) tex.print ('\\\\') tex.print ('M = ') M : print () \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} A = {{1,2},{1,-1}} tex.print ('A = ') print_array (A) tex.print (' or ') print_matrix (A) M = matrix : new ({{1,1},{0,2}}) tex.print ('\\\\') tex.print ('M = ') M : print () \end{tkzelements} \end{minipage} % subsubsection display_a_table_or_array_function_code_print_array (end) \subsubsection{Get an element of a matrix: method \Imeth{matrix}{get}} % (fold) \label{ssub:get_an_element_of_a_matrix} \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} M = matrix : new {{1,2},{2,-1}} S = M: get(1,1) + M: get(2,2) tex.print(S) \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} M = matrix : new {{1,2},{2,-1}} S = M: get(1,1) + M: get(2,2) tex.print(S) \end{tkzelements} \end{minipage} % subsubsection get_an_element_of_a_matrix (end) \subsubsection{Inverse matrix: : method \Imeth{matrix}{inverse}} % (fold) \label{ssub:inverse_matrix} \begin{minipage}{.6\textwidth} \begin{Verbatim} \begin{tkzelements} A = matrix : new ({{1,2},{2,-1}}) tex.print("Inverse of $A = $") B = A : inverse () B : print () \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.4\textwidth} \begin{tkzelements} A = matrix : new ({{1,2},{2,-3}}) tex.print("Inverse of $A = $") B = A : inverse () B : print () \end{tkzelements} \end{minipage} % subsubsection inverse_matrix (end) \subsubsection{Inverse matrix with power syntax} % (fold) \label{ssub:inverse_matrix_with_power_syntax} \begin{minipage}{.6\textwidth} \begin{Verbatim} \begin{tkzelements} M = matrix : new ({{1,0,1},{1,2, 1},{0,-1,2}}) tex.print("$M = $") print_matrix (M) tex.print('\\\\') tex.print("Inverse of $M = M^{-1} = $") print_matrix (M^-1) \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.4\textwidth} \begin{tkzelements} M = matrix : new ({{1,0,1},{1,2,1},{0,-1,2}}) tex.print("$M = $") print_matrix (M) tex.print('\\\\') tex.print("Inverse of $M = M^{-1} = $") print_matrix (M^-1) \end{tkzelements} \end{minipage} % subsubsection inverse_matrix_with_power_syntax (end) \subsubsection{Transpose matrix: method \Imeth{matrix}{transpose}} % (fold) \label{ssub:transpose_matrix} A transposed matrix can be accessed with |A: transpose ()| or with |A^{'T'}|. \vspace{.5em} \begin{minipage}{.6\textwidth} \begin{Verbatim} \begin{tkzelements} A = matrix : new ({{1,2},{2,-1}}) AT = A : transpose () tex.print("$A^{'T'} = $") AT : print () \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.4\textwidth} \begin{tkzelements} A = matrix : new ({{1,2},{2,-1}}) AT = A : transpose () tex.print("$A^{'T'} = $") AT : print () \end{tkzelements} \end{minipage} \vspace{.5em} Remark: |(A ^'T')^'T' = A| % subsubsection transpose_matrix (end) % subsection methods_of_the_class_matrix (end) \subsubsection{Method method \Imeth{matrix}{adjugate}} % (fold) \label{ssub:method_adjugate} \begin{minipage}{.6\textwidth} \begin{Verbatim} \begin{tkzelements} N = matrix : new {{1, 0, 3},{2, 1, 0},{-1, 2, 0}} tex.print('N = ') print_matrix(N) tex.print('\\\\') N.a = N : adjugate () N.i = N * N.a tex.print('adj(N) = ') N.a : print () tex.print('\\\\') tex.print('N $\\times$ adj(N) = ') print_matrix(N.i) tex.print('\\\\') tex.print('det(N) = ') tex.print(N.det) \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.4\textwidth} \begin{tkzelements} N = matrix : new {{1, 0, 3},{2, 1, 0},{-1, 2, 0}} tex.print('N = ') print_matrix(N) N.a = N : adjugate () N.i = N * N.a tex.print('adj(N) = ') N.a : print () tex.print('\\\\') tex.print('N $\\times$ adj(N) = ') print_matrix(N.i) tex.print('\\\\') tex.print('det(N) = ') tex.print(N.det) \end{tkzelements} \end{minipage} % subsubsection method_adjugate (end) \subsubsection{Method method \Imeth{matrix}{identity}}% (fold) \label{ssub:methode_identity} Creating the identity matrix order 3 \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} Id_3 = matrix : identity (3) Id_3 : print () \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} Id_3 = matrix : identity (3) Id_3 : print () \end{tkzelements} \end{minipage} % subsubsection methode_identity (end) \newpage \subsubsection{Diagonalization: method \code{diagonalize}} % (fold) \label{ssub:diagonalization} For the moment, this method only concerns matrices of order 2. \begin{minipage}{.5\textwidth} \begin{Verbatim} \begin{tkzelements} A = matrix : new {{5,-3}, {6,-4}} tex.print('A = ') A : print () D,P = A : diagonalize () tex.print('D = ') D : print () tex.print('P = ') P : print () R = P^(-1)*A*P tex.print('\\\\') tex.print('Test: $D = P^{-1}AP = $ ') R : print () tex.print('\\\\') tex.print('Verification: $P^{-1}P = $ ') T = P^(-1)*P T : print () \end{tkzelements} \end{Verbatim} \end{minipage} \begin{minipage}{.5\textwidth} \begin{tkzelements} A = matrix : new {{5,-3}, {6,-4}} tex.print('A = ') A : print () D,P = A : diagonalize () tex.print('D = ') D : print () tex.print('P = ') P : print () R = P^(-1)*A*P tex.print('\\\\') tex.print('Test: $D = P^{-1}AP = $ ') R : print () tex.print('\\\\') tex.print('Verification: $P^{-1}P = $ ') T = P^(-1)*P T : print () \end{tkzelements} \end{minipage} % subsubsection diagonalization (end) \subsubsection{Method \Imeth{matrix}{is\_orthogonal}} % (fold) \label{ssub:method_is_orthogonal} The method returns \code{true} if the matrix is orthogonal and \code{false} otherwise. \begin{Verbatim} \begin{tkzelements} local cos = math.cos local sin = math.sin local pi = math.pi A = matrix : new ({{cos(pi/6),-sin(pi/6)}, {sin(pi/6),cos(pi/6)}}) A : print () bool = A : is_orthogonal () tex.print('\\\\') if bool then tex.print("The matrix is orthogonal") else tex.print("The matrix is not orthogonal") end tex.print('\\\\') tex.print('Test: $A^T = A^{-1} ?$') print_matrix(transposeMatrix (A)) tex.print('=') inv_matrix (A) : print () \end{tkzelements} \end{Verbatim} \begin{tkzelements} local cos = math.cos local sin = math.sin local pi = math.pi A = matrix : new ({{cos(pi/6),-sin(pi/6)}, {sin(pi/6),cos(pi/6)}}) A : print () bool = A : is_orthogonal () tex.print('\\\\') if bool then tex.print("The matrix is orthogonal") else tex.print("The matrix is not orthogonal") end tex.print('\\\\') tex.print('Test: $A^T = A^{-1} ?$') print_matrix(transposeMatrix (A)) tex.print('=') inv_matrix (A) : print () \end{tkzelements} % subsubsection method_is_orthogonal (end) \subsubsection{Method \Imeth{matrix}{is\_diagonal}} % (fold) \label{ssub:method_is_diagonal} The method returns \code{true} if the matrix is diagonal and \code{false} otherwise. % subsubsection method_is_diagonal (end) % section matrices (end)