Ask Your Question

Revision history [back]

When you write var('i'), you define i as a symbol. In particular, 2*i is an element of the symbolic ring, not the rationals, but you ask that 2*i be an entry of a matrix whose coefficients are rationals (because of the QQ at the beginnig).

If you want the imaginary number, you should use the already defined I, if you want a matrix over, say the algabraic numbers (so that I in an element), you should write:

sage: matrix(QQbar,2,2,[[2*I,-2],[3,4]])
[2*I  -2]
[  3   4]

When you write var('i'), you define i as a symbol. In particular, 2*i is an element of the symbolic ring, not the rationals, but you ask that 2*i be an entry of a matrix whose coefficients are rationals (because of the QQ at the beginnig).

If you want the imaginary number, you should use the already defined I, if you want a matrix over, say the algabraic numbers QQbar (so that I in an element), you should write:

sage: matrix(QQbar,2,2,[[2*I,-2],[3,4]])
[2*I  -2]
[  3   4]