Ask Your Question
1

matrix base ring changes by a complex multiplication

asked 2020-01-15 10:59:29 +0200

cxrjdd gravatar image

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 flag offensive close merge delete

Comments

Just use CDF(I) instead of I

FrédéricC gravatar imageFrédéricC ( 2020-01-15 13:41:14 +0200 )edit

Thank you very much.

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

1 Answer

Sort by » oldest newest most voted
1

answered 2020-01-15 13:42:50 +0200

rburing gravatar image

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.

edit flag offensive delete link more

Comments

1

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

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

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: 2020-01-15 10:59:29 +0200

Seen: 214 times

Last updated: Jan 15 '20