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
return Matrix.empty if size == 0
rows = Array.new(size) {|j|
row = Array.new(size, 0)
row[j] = values[j]
row
}
new rows
end