I have a solution in the form
Root[a + b #1 + c #1^2 &, 1]
with {a,b,c} very long symbolic expressions How can I extract the coefficient {a,b,c}? I'd like to obtain a result like
coeff={a,b,c}
If your starting point is an explicit number (i.e. it has no symbolic parameters), then you could use MinimalPolynomial
and CoefficientList
.
This works with a Root
object ...
MinimalPolynomial[Root[1 + 2 #1 + #1^5 &, 1], x]
(* 1 + 2 x + x^5 *)
CoefficientList[%, x]
(* {1, 2, 0, 0, 0, 1} *)
... or any other algebraic number.
MinimalPolynomial[Sqrt[2] + Sqrt[3], x]
(* 1 - 10 x^2 + x^4 *)
CoefficientList[%, x]
(* {1, 0, -10, 0, 1} *)
Do keep in mind that MinimalPolynomial will aim to generate a polynomial with integer coefficients. Thus be aware of results like this:
MinimalPolynomial[Root[1 + 2 #1 + Sqrt[2] #1^2 &, 1], x]
(* -1 - 4 x - 4 x^2 + 2 x^4 *)
Your example is automatically evaluated into the quadratic solution
Root[a + b #1 + c #1^2 &, 1]
(* -(b/(2 c)) - 1/2 Sqrt[(b^2 - 4 a c)/c^2] *)
To maintain the Root
form, the polynomial must be a higher order. For example,
expr = Root[a + b #1 + c #1^5 &, 1]
(* Root[a + b #1 + c #1^5 &, 1] *)
Just use the first argument of Root
to form a polynomial in x and then use CoefficientList
CoefficientList[expr[[1]][x], x]
(* {a, b, 0, 0, 0, c} *)