ReplaceDiagonal
Returns a matrix with its main diagonal replaced by a given vector.
Syntax
-
ReplaceDiagonal(A, v)-
Ais a matrix -
vis a vector
-
Description
If A is an m×n matrix and v a vector of dimension min(m, n), then ReplaceDiagonal(A, v) returns the matrix obtained from A by replacing its main diagonal with the components of v (in order).
Examples
A ≔ ❨❨5, 1, 2, 3, 4❩, ❨4, 0, 2, 1, 7❩, ❨6, 3, 0, 4, 7❩, ❨4, 5, 2, 3, 9❩, ❨4, 0, 1, 2, 5❩❩
⎛5 1 2 3 4⎞ ⎜4 0 2 1 7⎟ ⎜6 3 0 4 7⎟ ⎜4 5 2 3 9⎟ ⎝4 0 1 2 5⎠
ReplaceDiagonal(A, ❨1, 0, 1, 0, 1❩)
⎛1 1 2 3 4⎞ ⎜4 0 2 1 7⎟ ⎜6 3 1 4 7⎟ ⎜4 5 2 0 9⎟ ⎝4 0 1 2 1⎠