Ask Your Question
0

How to eliminate denominators

asked 2023-05-08 19:40:57 +0100

8moeb8 gravatar image

Hi, I am trying to solve a system of linear equations symbolically, but the returned answers contain a common factor (probably signifies that the solution space is one-dimensional) and a common denominator. Is there a way to reduce them to the simplest form?

I am also interested in learning how one can turn a system of linear equations into matrix form.

Thank you!

edit retag flag offensive close merge delete

Comments

Please provide a code example and the expected result.

Max Alekseyev gravatar imageMax Alekseyev ( 2023-05-08 19:54:45 +0100 )edit

Like Max, I'm expecting clarification on ypur problem (i. e. sample code...).

For more enlightment, have a look at Robert Beezer's book, whic covers a lot of a first course in linear algebra, and a lot of Sage code related to this topic. And, as always, this free book is a sine qua non of learning to use Sage efficiently.

Finally, a hint : gcd?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-05-08 20:26:08 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-05-09 08:54:03 +0100

Emmanuel Charpentier gravatar image

While expecting a real example, let's look at a possible application : explicit inverse of a matrix. Let

sage: M=matrix(var("m", n=9), nrows=3) ; M
[m0 m1 m2]
[m3 m4 m5]
[m6 m7 m8]

Its inverse is hardly legible :

sage: IM=(M^-1).apply_map(factor) ; IM
[ (m5*m7 - m4*m8)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8) -(m2*m7 - m1*m8)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8)  (m2*m4 - m1*m5)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8)]
[-(m5*m6 - m3*m8)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8)  (m2*m6 - m0*m8)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8) -(m2*m3 - m0*m5)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8)]
[ (m4*m6 - m3*m7)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8) -(m1*m6 - m0*m7)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8)  (m1*m3 - m0*m4)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8)]

The common denominator of the nine elements of this inverse is theit greatest common denominator, which can be computed by gcd :

sage: D=gcd(map(denominator, flatten(IM.list()))).factor() ; D
m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8

and the inverse $IM$ can be written as the product of the inverse of this common denominator $D$ and the product of the original matrix by this denominator $\left(M\cdot D\right)$, which is :

sage: SIM = (IM*D).apply_map(factor) ; SIM
[ m5*m7 - m4*m8 -m2*m7 + m1*m8  m2*m4 - m1*m5]
[-m5*m6 + m3*m8  m2*m6 - m0*m8 -m2*m3 + m0*m5]
[ m4*m6 - m3*m7 -m1*m6 + m0*m7  m1*m3 - m0*m4]

The stucture of the inverse is much more understandable : one can almost "see" the Sarrus algorithm at work...

Check :

sage: SIM/D==IM
True

HTH,

edit flag offensive delete link more

Comments

Thank you! Got it :-)

8moeb8 gravatar image8moeb8 ( 2023-05-10 01:25:23 +0100 )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: 2023-05-08 19:40:57 +0100

Seen: 323 times

Last updated: May 09 '23