I am using IPython (Anaconda distribution) with the sympy symbolic maths library.
I have the following expression:
t⋅(h + l)
───────────────────────
l⋅(h + l⋅sin(θ))⋅cos(θ)
I would like to rearrange this to get it in terms of (h/l)
and (t/l)
:
(t/l)⋅((h/l)+1)
─────────────────────
((h/l)+sin(θ))⋅cos(θ)
This is quite easy to do by hand; just divide both sides of the fraction by l
and rearrange.
So far I have had no luck with sympy's built in functions.
I have tried using expand
followed by collect(expr,h/l)
, but it doesn't change the expression. I suspect this doesn't work because there are no h/l
terms for it to collect in the first place.
How do I get sympy to do this?
Python code for the first expression to save you time:
t*(h + l)/(l*(h + l*sin(theta))*cos(theta))