2
$\begingroup$

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
$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$
    – LouisB
    Apr 14, 2017 at 22:31
  • 1
    $\begingroup$ CoefficientList[3 x^2 + 2 x + 4, x] yields {c, b, a}. $\endgroup$
    – Michael E2
    Apr 14, 2017 at 22:52

1 Answer 1

3
$\begingroup$

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}}
$\endgroup$
1
  • $\begingroup$ Awesome, thanks! $\endgroup$
    – Jordan
    Apr 15, 2017 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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