Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Rounding entries of a random vector

Hello, I am trying to generate a random diagonal matrix, defined by a random vector over a field RR. The problem is that I need to round all the values to two decimal places, make entries evenly positive and negative (not necessary of equal amount) and, ideally, avoid zeroes. I have a code [round(4*random()-2,2)for i in[1 .. 8]] that produces a list of values that I need of size 8. However, I am struggling to combine it with a command diagonal_matrix and insert it there.

Also, I don't really understand why do we need to multiply it by 4 in here [round(4*random()-2,2)for i in[1 .. 8]] and why it produces negative values only, if I multiply it by 2 instead of 4. Could someone explain it please? Is there any other simpler and more elegant way to solve this problem? Thank you.

Rounding entries of a random vector

Hello, I am trying to generate a random diagonal matrix, defined by a random vector over a field RR. The problem is that I need to round all the values to two decimal places, make entries evenly positive and negative (not necessary of equal amount) and, ideally, avoid zeroes. I have a code

[round(4*random()-2,2)for i in[1 .. 8]]

that produces a list of values that I need of size 8. However, I am struggling to combine it with a command diagonal_matrix and insert it there.

Also, I don't really understand why do we need to multiply it by 4 in here [round(4*random()-2,2)for i in[1 .. 8]] and why it produces negative values only, if I multiply it by 2 instead of 4. Could someone explain it please? Is there any other simpler and more elegant way to solve this problem? Thank you. you.

Rounding entries of a random vector

Hello, I am trying to generate a random diagonal matrix, defined by a random vector over a field RR. The problem is that I need to round all the values to two decimal places, make entries evenly positive and negative (not necessary of equal amount) and, ideally, avoid zeroes. I have a code

[round(4*random()-2,2)for i in[1 .. 8]]

that produces a list of values that I need of size 8. However, I am struggling to combine it with a command diagonal_matrix and insert it there.

Also, I don't really understand why do we need to multiply it by 4 in here [round(4*random()-2,2)for i in[1 .. 8]] and why it produces negative values only, if I multiply it by 2 instead of 4. Could someone explain it please? Is there any other simpler and more elegant way to solve this problem? Thank you.

Rounding entries of a random vector

Hello, I am trying to generate a random diagonal matrix, defined by a random vector over a field RR. The problem is that I need to round all the values to two decimal places, make entries evenly positive and negative (not necessary of equal amount) and, ideally, avoid zeroes. I have a code

[round(4*random()-2,2)for i in[1 .. 8]]

that produces a list of values that I need of size 8. However, I am struggling to combine it with a command diagonal_matrix and insert it there.

Also, I don't really understand why do we need to multiply it by 4 in here

[round(4*random()-2,2)for i in[1 .. 8]]

and why it produces negative values only, if I multiply it by 2 instead of 4. Could someone explain it please? Is there any other simpler and more elegant way to solve this problem? Thank you.