ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 21 Nov 2017 14:53:11 +0100Rounding entries of a random vectorhttps://ask.sagemath.org/question/39697/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.XeniaTue, 21 Nov 2017 14:53:11 +0100https://ask.sagemath.org/question/39697/'object is not callable' error in sagetex (that doesn't occur in a worksheet)https://ask.sagemath.org/question/35766/object-is-not-callable-error-in-sagetex-that-doesnt-occur-in-a-worksheet/I'm generating random numbers to be presented in scientific notation for a quiz I'm typing. In testing this code works fine in a worksheet, but gives an error in a sagesilent block of my .tex document. Here's the code:
sci = {}
for index in range(1, 14): # Picks random coeffs for sci not.
places = ZZ.random_element(0, 4)
sci["co{0}".format(index)] = round(10*random(), places)
powe = {}
for index in range(1, 14): # Picks random powers for use.
powe["r{0}".format(index)] = ZZ.random_element(5, 10)
sci['co1']
sci['co2']
powe['r1']
powe['r2']
In the worksheet, those last four lines generate output like
3.0
5.566
7
8
But when I use that same code in the .tex document (without the last four lines), Sage returns this error before I can even call my numbers:
'module' object is not callable
My best guess is that rounding needs some package that the worksheet imports automatically but sagetex does not, but I'm afraid I don't know enough about what's really going on. Thank you for any help!mathochistMon, 28 Nov 2016 20:00:55 +0100https://ask.sagemath.org/question/35766/