Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Okay, combining the other two answers, how about this:

sage: M = matrix([[1,0,0],[0,1-x^2/2 +x^3,-x],[0,x,1- x^2/2]])
sage: parent(M)
Full MatrixSpace of 3 by 3 dense matrices over Symbolic Ring
sage: 
sage: R.<x> = PolynomialRing(QQ)
sage: 
sage: # change the base ring of M
sage: M = M.change_ring(R)
sage: parent(M)
Full MatrixSpace of 3 by 3 dense matrices over Univariate Polynomial Ring in x over Rational Field
sage: 
sage: for i in (0..4):
....:     print i
....:     print M.apply_map(lambda x: x.truncate(i))
....: 
0
[0 0 0]
[0 0 0]
[0 0 0]
1
[1 0 0]
[0 1 0]
[0 0 1]
2
[ 1  0  0]
[ 0  1 -x]
[ 0  x  1]
3
[           1            0            0]
[           0 -1/2*x^2 + 1           -x]
[           0            x -1/2*x^2 + 1]
4
[                1                 0                 0]
[                0 x^3 - 1/2*x^2 + 1                -x]
[                0                 x      -1/2*x^2 + 1]