# Finding roots of equation in table form

I would like to find roots of legendre polynomial NRoots[LegendreP[4, x]== 0, x] , I'm getting
x == -0.861136 || x == -0.339981 || x == 0.339981 || x == 0.861136 as output.

Instead i need my output as { -0.861136 , -0.339981 , 0.339981 ,0.861136}

Could you please suggest me what type of modification i should make in input code so that i get my output as { -0.861136 , -0.339981 , 0.339981 ,0.861136}

• Use NSolve[] instead: x /. NSolve[LegendreP[4, x] == 0, x]. Apr 6, 2017 at 2:25
• @J.M. Aside from the format, I would assume that NRoots and NSolve use different algorithms, so, conceivably, the OP would like to use the former for algorithmic reasons?! Apr 6, 2017 at 3:28

If you prefer NRoots to NSolve as suggested by J.M., you can do

x /. Rule @@ # & /@ (List @@ NRoots[LegendreP[4, x] == 0, x]

• I'd use ToRules[] myself if the OP insists on using NRoots[]: x /. {ToRules[NRoots[LegendreP[4, x] == 0, x]]}. Apr 6, 2017 at 3:33

For your specified problem you can Solve for exact solutions

roots = Simplify[x /. Solve[LegendreP[4, x] == 0, x]]


Verifying,

LegendreP[4, #] & /@ roots

(*  {0, 0, 0, 0}  *)


Then, if desired, use N with any desired precision

roots // N[#, 20] &

(*  {-0.33998104358485626480, 0.33998104358485626480,
-0.86113631159405257522, 0.86113631159405257522}  *)