Search code examples
pythonsympynumeric

How do I get the results with the root resolved in python?


How do I get the results with the root resolved.

a = Eq(x**3 + x**2 - 3*x + 1,0)

b = solve(a)

print(b)

results:

[1, -1 + sqrt(2), -sqrt(2) - 1]

Solution

  • Use evalf:

    In [4]: [s.evalf() for s in b]                                                                                                                 
    Out[4]: [1.0, 0.414213562373095, -2.41421356237309]