Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I have an equation of the form

$$u s + \frac{1}{v} + \frac{1}{p s + q} = 0$$

(or any form that can be written as a standard quadratic, really, the above form is just an example; they'll all be equal to 0 from the start, however) and I want it in the form

$$ s^2 + b s + c = 0 $$ i.e. the coefficient on $s^2$ is 1.

How do I do this using Mathematica? More specifically, I'm interested in finding $b$ and $c$, but if the equation is written in this form, grouped properly, doing that is very easy by eye.

share|improve this question
up vote 5 down vote accepted

You can combine the terms to a common denominator using Together:

Together[u s + 1/v + 1/(p s + q)]

$\displaystyle\frac{p u v s^2 +p s+q s u v+q+v}{v (p s+q)}$

Now, assuming $v (p s+q)\neq 0$, you can get your coefficients $c$ and $b$ respectively as:

Most@#/Last@# &@CoefficientList[Numerator[Together[u s + 1/v + 1/(p s + q)]], s]
(* {(q + v)/(p u v), (p + q u v)/(p u v)} *)
share|improve this answer
It's hard to pick an answer when both answers work great and were posted less than two minutes apart! In the end, I went by time posted. Thanks to both of you, though. – exscape May 30 '12 at 6:55

Assuming that your equations are quadratic in $s$, here's one way:

(Collect[#/Coefficient[#, s, 2], s]) &[Numerator[Together[u s + 1/v + 1/(p s + q)]]]
s^2 + (q + v)/(p u v) + (s (p + q u v))/(p u v)

If it's just the coefficients you want:

(CoefficientList[#/Coefficient[#, s, 2], s]) &[Numerator[Together[u s + 1/v + 1/(p s + q)]]]
{1/(p u) + q/(p u v), q/p + 1/(u v), 1}

Note the convention of putting the constant term first and leading coefficient last.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.