Previous Up Next

2.41.4  Diagonal of a matrix or matrix of a diagonal : BlockDiagonal diag

diag or BlockDiagonal takes as argument a matrix A or a list l.
diag returns the diagonal of A or the diagonal matrix with the list l on the diagonal (and 0 elsewhere).
Input :

diag([[1,2],[3,4]])

Output :

[1,4]

Input :

diag([1,4])

Output :

[[1,0],[0,4]]

Previous Up Next