Skip to content

set_diagonal_matrixSetDiagonalMatrixSetDiagonalMatrixset_diagonal_matrixT_set_diagonal_matrix🔗

Short description🔗

set_diagonal_matrixSetDiagonalMatrixSetDiagonalMatrixset_diagonal_matrixT_set_diagonal_matrix — Set the diagonal elements of a matrix.

Signature🔗

set_diagonal_matrix( matrix MatrixID, matrix VectorID, integer Diagonal )void SetDiagonalMatrix( const HTuple& MatrixID, const HTuple& VectorID, const HTuple& Diagonal )static void HOperatorSet.SetDiagonalMatrix( HTuple matrixID, HTuple vectorID, HTuple diagonal )def set_diagonal_matrix( matrix_id: HHandle, vector_id: HHandle, diagonal: int ) -> None

Herror T_set_diagonal_matrix( const Htuple MatrixID, const Htuple VectorID, const Htuple Diagonal )

void HMatrix::SetDiagonalMatrix( const HMatrix& VectorID, Hlong Diagonal ) const

void HMatrix.SetDiagonalMatrix( HMatrix vectorID, int diagonal )

Description🔗

The operator set_diagonal_matrixSetDiagonalMatrix overwrites the diagonal elements of the Matrix with the elements of the matrix Vector. The matrices are defined by their matrix handles MatrixIDmatrixIDmatrix_id and VectorIDvectorIDvector_id. The matrix Vector must have one column and one row, \(n\) columns and one row or one column and \(n\) rows. \(n\) is the number of elements to be set in the Matrix (see below). If the matrix Vector has one column and one row, i.e., the matrix has one value, each element of the diagonal of the Matrix is overwritten by this value. Otherwise, the diagonal is overwritten by the elements of the matrix Vector.

If Diagonaldiagonaldiagonal = 0, the main diagonal of the Matrix is overwritten. The number \(n\) = min(number of rows of Matrix, number of columns of Matrix).

Example 1:

\[\begin{eqnarray*} \texttt{Matrix} = \left[ \begin{array}{rrrr} 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \end{array} \right] \end{eqnarray*}\]
\[\begin{eqnarray*} \texttt{Vector} = \left[ \begin{array}{rrr} 3.0 & 7.0 & 1.0 \\ \end{array} \right] \qquad \textrm{Diagonal} = 0 \end{eqnarray*}\]
\[\begin{eqnarray*} \to \qquad \texttt{Matrix} = \left[ \begin{array}{rrrr} 3.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 7.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 1.0 & 0.0 \end{array} \right] \end{eqnarray*}\]

Example 2:

\[\begin{eqnarray*} \texttt{Matrix} = \left[ \begin{array}{rrrr} 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \end{array} \right] \end{eqnarray*}\]
\[\begin{eqnarray*} \texttt{Vector} = \left[ \begin{array}{r} 3.0 \\ \end{array} \right] \qquad \textrm{Diagonal} = 0 \end{eqnarray*}\]
\[\begin{eqnarray*} \to \qquad \texttt{Matrix} = \left[ \begin{array}{rrrr} 3.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 3.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 3.0 & 0.0 \end{array} \right] \end{eqnarray*}\]

If Diagonaldiagonaldiagonal is positive, the Diagonaldiagonaldiagonal-th super-diagonal of Matrix is overwritten. For the example 1 the number \(n\) = min(number of rows of Matrix, parameter Diagonaldiagonaldiagonal). For the example 2 the number \(n\) = min(number of rows of Matrix, number of columns of Matrix).

Example 1:

\[\begin{eqnarray*} \texttt{Matrix} = \left[ \begin{array}{rrrr} 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \end{array} \right] \end{eqnarray*}\]
\[\begin{eqnarray*} \texttt{Vector} = \left[ \begin{array}{rr} -2.0 & 6.0 \\ \end{array} \right] \qquad \textrm{Diagonal} = 2 \end{eqnarray*}\]
\[\begin{eqnarray*} \to \qquad \texttt{Matrix} = \left[ \begin{array}{rrrr} 0.0 & 0.0 & -2.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 6.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \end{array} \right] \end{eqnarray*}\]

Example 2:

\[\begin{eqnarray*} \texttt{Matrix} = \left[ \begin{array}{rrrr} 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \end{array} \right] \end{eqnarray*}\]
\[\begin{eqnarray*} \texttt{Vector} = \left[ \begin{array}{r} -2.0 \\ \end{array} \right] \qquad \textrm{Diagonal} = 2 \end{eqnarray*}\]
\[\begin{eqnarray*} \to \qquad \texttt{Matrix} = \left[ \begin{array}{rrrr} 0.0 & 0.0 & -2.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & -2.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \end{array} \right] \end{eqnarray*}\]

If Diagonaldiagonaldiagonal is negative, the Diagonaldiagonaldiagonal-th sub-diagonal of Matrix is overwritten. For the example 1 the number \(n\) = min(number of columns of Matrix, parameter Diagonaldiagonaldiagonal). For the example 2 the number \(n\) = min(number of rows of Matrix, number of columns of Matrix).

Example 1:

\[\begin{eqnarray*} \texttt{Matrix} = \left[ \begin{array}{rrrr} 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \end{array} \right] \end{eqnarray*}\]
\[\begin{eqnarray*} \texttt{Vector} = \left[ \begin{array}{rr} -5.0 & -4.0 \\ \end{array} \right] \qquad \textrm{Diagonal} = -1 \end{eqnarray*}\]
\[\begin{eqnarray*} \to \qquad \texttt{Matrix} = \left[ \begin{array}{rrrr} 0.0 & 0.0 & 0.0 & 0.0 \\ -5.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & -4.0 & 0.0 & 0.0 \end{array} \right] \end{eqnarray*}\]

Example 2:

\[\begin{eqnarray*} \texttt{Matrix} = \left[ \begin{array}{rrrr} 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & 0.0 \end{array} \right] \end{eqnarray*}\]
\[\begin{eqnarray*} \texttt{Vector} = \left[ \begin{array}{r} -5.0 \end{array} \right] \qquad \textrm{Diagonal} = -1 \end{eqnarray*}\]
\[\begin{eqnarray*} \to \qquad \texttt{Matrix} = \left[ \begin{array}{rrrr} 0.0 & 0.0 & 0.0 & 0.0 \\ -5.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & -5.0 & 0.0 & 0.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.

This operator modifies the state of the following input parameter:

During execution of this operator, access to the value of this parameter must be synchronized if it is used across multiple threads.

Parameters🔗

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

Matrix handle of the input matrix.

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

Matrix handle containing the diagonal elements to be set.

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

Position of the 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

Result🔗

If the parameters are valid, the operator set_diagonal_matrixSetDiagonalMatrix 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

get_diagonal_matrixGetDiagonalMatrix

Module🔗

Foundation