Ask Your Question
0

Run LCM fractions

asked 2015-12-30 09:12:07 -0500

Caterpillar gravatar image

I am doing some matrix multiplications, and as result I get

image description

Now see position 1,1 of the matrix: I want SageMath to return me a result that has only one fraction (using LCM), not two fractions. Which command should I use?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2015-12-30 09:58:21 -0500

Rational fractions are not simplified by default

sage: x = SR.var('x')
sage:  f = 1/(x-2) + 1/(x-3)
sage: f
1/(x - 2) + 1/(x - 3)

If you want to get one fraction just do

sage: f.simplify_rational()
(2*x - 5)/(x^2 - 5*x + 6)

The same manipulation applies for matrices

sage: m = matrix(2, [1/x, 1/(x+1), 1/(x+1), 1/x])
sage: m2 = m*m
sage: m2
[1/(x + 1)^2 + 1/x^2       2/((x + 1)*x)]
[      2/((x + 1)*x) 1/(x + 1)^2 + 1/x^2]
sage: m2.simplify_rational()
[(2*x^2 + 2*x + 1)/(x^4 + 2*x^3 + x^2)                           2/(x^2 + x)]
[                          2/(x^2 + x) (2*x^2 + 2*x + 1)/(x^4 + 2*x^3 + x^2)]
edit flag offensive delete link more

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: 2015-12-30 09:12:07 -0500

Seen: 31 times

Last updated: Dec 30 '15