CoCoA:DiagonalMat

From ApCoCoAWiki

DiagonalMat

matrix with given diagonal

Description

This function (equivalently DiagMat) returns the diagonal matrix

whose diagonal are the elements of the list L.

Example

  DiagonalMat([3,4,5]);
Mat([
  [3, 0, 0],
  [0, 4, 0],
  [0, 0, 5]
])
-------------------------------

-- fast implementation for high powers of a diagonal matrix
  Define PowerDiag(M, Exp)
    If Not IsDiagonal(M) Then Error(<quotes>PowerDiag: matrix must be diagonal</quotes>); EndIf;
    Return DiagonalMat([ M[I,I]^Exp | I In 1..Len(M) ]);
  EndDefine;

  PowerDiag(Identity(3), 200000000);
Mat([
  [1, 0, 0],
  [0, 1, 0],
  [0, 0, 1]
])
-------------------------------

Syntax

DiagonalMat(L:LIST):MAT
DiagMat(L:LIST):MAT

BlockMatrix

IsDiagonal

ColMat

RowMat

   <type>matrix</type>