Skip to content

get_diagonal_matrixGetDiagonalMatrixGetDiagonalMatrixget_diagonal_matrixT_get_diagonal_matrix🔗

Short description🔗

get_diagonal_matrixGetDiagonalMatrixGetDiagonalMatrixget_diagonal_matrixT_get_diagonal_matrix — Get the diagonal elements of a matrix.

Signature🔗

get_diagonal_matrix( matrix MatrixID, integer Diagonal, out matrix VectorID )void GetDiagonalMatrix( const HTuple& MatrixID, const HTuple& Diagonal, HTuple* VectorID )static void HOperatorSet.GetDiagonalMatrix( HTuple matrixID, HTuple diagonal, out HTuple vectorID )def get_diagonal_matrix( matrix_id: HHandle, diagonal: int ) -> HHandle

Herror T_get_diagonal_matrix( const Htuple MatrixID, const Htuple Diagonal, Htuple* VectorID )

HMatrix HMatrix::GetDiagonalMatrix( Hlong Diagonal ) const

HMatrix HMatrix.GetDiagonalMatrix( int diagonal )

Description🔗

The operator get_diagonal_matrixGetDiagonalMatrix generates a new matrix Vector and copies the diagonal elements of the Matrix to this new matrix. The Matrix is defined by the matrix handle MatrixIDmatrixIDmatrix_id. The matrix Vector has one column and \(n\) rows, where \(n\) = number of diagonal elements. The operator returns the matrix handle VectorIDvectorIDvector_id of the matrix Vector. Access to the elements of the matrix is possible e.g., with the operator get_full_matrixGetFullMatrix.

If Diagonaldiagonaldiagonal = 0, the output of the Vector is the main diagonal of the Matrix.

Example:

Diagonaldiagonaldiagonal = 00

\[\begin{eqnarray*} \texttt{Matrix} = \left[ \begin{array}{rrr} 3.0 & 1.0 & -2.0 \\ -5.0 & 7.0 & 2.0 \\ -9.0 & -4.0 & 1.0 \end{array} \right] \end{eqnarray*}\]
\[\begin{eqnarray*} \qquad \to \texttt{Vector} = \left[ \begin{array}{r} 3.0 \\ 7.0 \\ 1.0 \end{array} \right] \end{eqnarray*}\]

If Diagonaldiagonaldiagonal is positive, the output Vector is the Diagonaldiagonaldiagonal-th super-diagonal of the Matrix.

Example:

Diagonaldiagonaldiagonal = 22

\[\begin{eqnarray*} \texttt{Matrix} = \left[ \begin{array}{rrrr} 3.0 & 1.0 & -2.0 & 1.0 \\ -5.0 & 7.0 & 2.0 & 6.0 \\ -9.0 & -4.0 & 1.0 & -1.0 \end{array} \right] \end{eqnarray*}\]
\[\begin{eqnarray*} \qquad \to \qquad \texttt{Vector} = \left[ \begin{array}{r} -2.0 \\ 6.0 \end{array} \right] \end{eqnarray*}\]

If Diagonaldiagonaldiagonal is negative, the Diagonaldiagonaldiagonal-th sub-diagonal of the Matrix is copied.

Example:

Diagonaldiagonaldiagonal = -1-1

\[\begin{eqnarray*} \texttt{Matrix} = \left[ \begin{array}{rrrr} 3.0 & 1.0 & -2.0 & 1.0 \\ -5.0 & 7.0 & 2.0 & 6.0 \\ -9.0 & -4.0 & 1.0 & -1.0 \end{array} \right] \end{eqnarray*}\]
\[\begin{eqnarray*} \qquad \to \qquad \texttt{Vector} = \left[ \begin{array}{r} -5.0 \\ -4.0 \end{array} \right] \end{eqnarray*}\]

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

Parameters🔗

MatrixIDmatrixIDmatrix_id (input_control) matrix → (handle)HTuple (HHandle)HMatrix, HTuple (IntPtr)HHandleHtuple (handle)

Matrix handle of the input matrix.

Diagonaldiagonaldiagonal (input_control) integer → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Number of the desired diagonal.

Default: 00
Suggested values: -20, -10, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 10, 20-20, -10, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 10, 20

VectorIDvectorIDvector_id (output_control) matrix → (handle)HTuple (HHandle)HMatrix, HTuple (IntPtr)HHandleHtuple (handle)

Matrix handle containing the diagonal elements.

Result🔗

If the parameters are valid, the operator get_diagonal_matrixGetDiagonalMatrix returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

Combinations with other operators🔗

Combinations

Possible predecessors

create_matrixCreateMatrix

Possible successors

get_full_matrixGetFullMatrix, get_value_matrixGetValueMatrix

See also

set_diagonal_matrixSetDiagonalMatrix

Module🔗

Foundation