# Extracting the coefficients of a quadratic equation

I'm just getting started with mathematica. I can ask mathematica to solve simple quadratic equations:

3x^2 + 2x + 4
Solve[3 x^2 + 2 x + 4 == 0, x]


And it returns the roots:

{{x -> 1/3 (-1 - I Sqrt[11])}, {x -> 1/3 (-1 + I Sqrt[11])}}


How could I instead get the constants of the quadratic equation: a, b, c?

ax^2 + bx + c == 3x^2 + 2x + 4

a = 3
b = 2
c = 4

• SolveAlways[a x^2 + b x + c == 3 x^2 + 2 x + 4, x]  Be careful to put a space between the coefficients and the independent variable, or use * for multiplication. Apr 14, 2017 at 22:31
• CoefficientList[3 x^2 + 2 x + 4, x] yields {c, b, a}. Apr 14, 2017 at 22:52

The (one) direct way is as follows: You get the coefficients of a polynomial with Coefficients. so if you have your equation as

eq = a x^2 + b x + c


and the "left side" as

ls = 3 x^2 + 2 x + 4


then

   Solve[MapThread[
Equal, {CoefficientList[eq, x], CoefficientList[ls, x]}]]


delivers

{{a -> 3, b -> 2, c -> 4}}

• Awesome, thanks! Apr 15, 2017 at 1:06