Ask Your Question
0

Conversion from a ring to another for matrix

asked 2020-05-27 02:32:21 -0600

Cyrille gravatar image

Suppose I have inherited of a matrix with real numbers that is X.yyyy style numbers. Is there a simple way to transform this matrix in a matrix composed of rational numbers and vis-versa ? And what if the matrix is composed of mixed numbers ? In that last case, could I impose a ring ?

Say M1=matrix(2, 2,(1.2,2.3564,3.0000,5.4321)), M2=matrix(2, 2,(1/2,2/6, 3/8,. 5.4321)), M3=matrix(2, 2,(1.2,3/4,1,2.756))

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2020-05-27 02:58:07 -0600

Sébastien gravatar image

The method change_ring is made for that:

sage: m = random_matrix(RDF, 3, 3)
sage: m
[  -0.5774223516523238    0.4648049987667806  -0.17171365230946778]
[-0.056437596814425284   -0.8482416820866097   -0.4433923816239411]
[  -0.8602958788377144   -0.6032286081857376    0.2704814323965121]
sage: m.change_ring(QQ)
[-122806609/212680733   66491472/143052403  -40134866/233731363]
[ -53603174/949777755  -91233993/107556602   -33210813/74901632]
[-538125967/625512664 -107008889/177393591   51117399/188986721]

Note that it does not change m:

sage: m
[  -0.5774223516523238    0.4648049987667806  -0.17171365230946778]
[-0.056437596814425284   -0.8482416820866097   -0.4433923816239411]
[  -0.8602958788377144   -0.6032286081857376    0.2704814323965121]
edit flag offensive delete link more

Comments

Nice I haven't found this command.Thanks.

Cyrille gravatar imageCyrille ( 2020-05-27 04:13:07 -0600 )edit

Note that this isn't a command but the use of a method (in this case belonging to the class of m). The list of methods that can be applied to m can be obtained by dir(m) ; perusing this list is often ... inspirational, shall we say...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-05-27 05:09:01 -0600 )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

1 follower

Stats

Asked: 2020-05-27 02:32:21 -0600

Seen: 31 times

Last updated: May 27 '20