Mathematica Asked on April 6, 2021
I have the following expression
-(((-(L/r1) + L/r2)^2*(L/r1 - L/r3)^2*(-(L/r2) + L/r3)^2)/(1 + 1/r1 + 1/r2 + 1/r3)^2) + (1 + L^2/r1 + ((-(L/r1) + L/r2)*(L/r1 - L/r3))/(1 + 1/r1 + 1/r2 + 1/r3))*
(1 + L^2/r2 + ((-(L/r1) + L/r2)*(-(L/r2) + L/r3))/(1 + 1/r1 + 1/r2 + 1/r3))*(1 + 1/r1 + 1/r2 + 1/r3)*(1 + ((L/r1 - L/r3)*(-(L/r2) + L/r3))/(1 + 1/r1 + 1/r2 + 1/r3) +
L^2/r3)
Which I want to rewrite by collecting according to the inverse powers of r1
, r2
and r3
. That is, I want to get
1 + (1 + L^2)/r1 + (1 + L^2)/r2 + (1 + L^2)/r3 + (3*L^2 + L^4)/(r1*r2) + (3*L^2 + L^4)/(r1*r3) + (3*L^2 + L^4)/(r2*r3) + (9*L^4 + L^6)/(r1*r2*r3) -
L^6/(r1^2*r2^2) - L^6/(r1^2*r3^2) - L^6/(r2^2*r3^2) + (2*L^6)/(r1*r2*r3^2) + (2*L^6)/(r1*r2^2*r3) + (2*L^6)/(r1^2*r2*r3)
I have done this by hand, but for more complciated expressions I want to use Mathematica. I tried Collect[expression,{r1,r2,r3},Simplify]
but it did nothing for me. Also, I do not want to collect in powers of L
.
Total @ Factor @ MonomialList[Simplify @ expr, 1/{r1, r2, r3}]
To have the terms in a specific order, sort the monomials as you like and wrap the resulting list with Apply[Defer @* Plus]
:
Apply[Defer @* Plus] @
SortBy[Through @ {Total, Sort} @ Exponent[#, 1/{r1, r2, r3}] &] @
Factor @ MonomialList[Simplify @ expr, 1/{r1, r2, r3}]
Using an alternative ordering of terms:
Apply[Defer @* Plus] @ Factor @
MonomialList[Simplify @ expr, 1/{r1, r2, r3}, "NegativeDegreeReverseLexicographic"]
Correct answer by kglr on April 6, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP