diagonal(*values)
public
Creates a matrix where the diagonal elements are composed of
values.
Matrix.diagonal(9, 5, -3)
=> 9 0 0
0 5 0
0 0 -3
Show source
def Matrix.diagonal(*values)
size = values.size
rows = (0 .. size - 1).collect {
|j|
row = Array.new(size).fill(0, 0, size)
row[j] = values[j]
row
}
rows(rows, false)
end