Ask Your Question
2

Changing number of decimal digits displayed in output

asked 2010-09-29 16:37:13 +0100

slearch gravatar image

updated 2011-04-28 16:51:28 +0100

Kelvin Li gravatar image

I am doing some computations with large matrices over the complex numbers. When these matrices are outputted, the entries appear, for example, as

[ 0.03661165235? - 0.08838834765?I 0.21338834765? + 0.08838834765?I 0.03661165235? + 0.08838834765?*I etc

I would like to change it so that the output only displays each entry to 3 decimal places, so that they are easier to see. Is there a way to do this? Is there a way to do this that doesn't alter the number of digits stored? For reference, my input is

P8 = diagonal_matrix([1,1,1,0,0,0,0,1,1,0,0,0, 0,1,1,1])

UP8U.inverse()

where U is a previously defined matrix with complex entries.

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2010-09-29 17:50:40 +0100

niles gravatar image

Here's one idea: pass the matrix to a low-precision ring before printing it -- this won't change the original matrix, just the printed version:

sage: CC10 = ComplexField(prec=10)
sage: MatPrint = MatrixSpace(CC10,3,3)
sage: M = Matrix(CC,3,3,[sqrt(-n) for n in range(9)])
sage: M.parent()
Full MatrixSpace of 3 by 3 dense matrices over Complex Field with 53 bits of precision
sage: M
[                                        0                        1.00000000000000*I 8.65956056235493e-17 + 1.41421356237309*I]
[1.06057523872491e-16 + 1.73205080756888*I                        2.00000000000000*I 1.36919674566051e-16 + 2.23606797749979*I]
[1.49987988652185e-16 + 2.44948974278318*I 1.62005543721758e-16 + 2.64575131106459*I 1.73191211247099e-16 + 2.82842712474619*I]
sage: MatPrint(M)
[              0           1.0*I 8.7e-17 + 1.4*I]
[1.1e-16 + 1.7*I           2.0*I 1.4e-16 + 2.2*I]
[1.5e-16 + 2.4*I 1.6e-16 + 2.6*I 1.7e-16 + 2.8*I]
sage: MatPrint(M).parent()
Full MatrixSpace of 3 by 3 dense matrices over Complex Field with 10 bits of precision
sage: M.parent()
Full MatrixSpace of 3 by 3 dense matrices over Complex Field with 53 bits of precision

There is also a Trac ticket for this, with a patch, but work on it seems to have stalled . . . if you decide you need to use it, you can check the developer guide for how to apply patches to Sage.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2010-09-29 16:37:13 +0100

Seen: 3,994 times

Last updated: Sep 29 '10