# matrix base ring changes by a complex multiplication

The complex multiplication of matrix changes the base ring.

A = matrix(CDF,[[1,2],[3,4]]); print(A)
B = 2*A
C = I*A
print(type(A))
print(type(B))
print(type(C))


The result is

[1.0 2.0]
[3.0 4.0]
<class 'sage.matrix.matrix_complex_double_dense.Matrix_complex_double_dense'>
<class 'sage.matrix.matrix_complex_double_dense.Matrix_complex_double_dense'>
<class 'sage.matrix.matrix_symbolic_dense.Matrix_symbolic_dense'>


So the multiplication by an imaginary number breaks the CDF property. This is very inconvenient for numerical calculations, because the symbolic computation is very slow.

edit retag close merge delete

Just use CDF(I) instead of I

( 2020-01-15 13:41:14 +0200 )edit

Thank you very much.

( 2020-01-21 20:46:35 +0200 )edit

Sort by » oldest newest most voted

Indeed this is an old issue: I.parent() should not be the symbolic ring [trac ticket #18036]. When you know your base field, you should use the $i$ from that base field. You can access it e.g. by CDF(I) or CDF.gens()[0] or CDF.0. If you have a complex number z which is not in your base field for whatever reason (e.g. it is symbolic, e.g. because you used I), then you can do CDF(z) to convert it into your base field. You can also change the ring of a matrix e.g. by C.change_ring(CDF); it returns a new matrix, over the new ring.

more

1

To obtain the CDF version of I you can also use CDF.gen() or CDF.gen(0).

( 2020-01-17 01:10:11 +0200 )edit