vikas_hada - 1 year ago 60

Python Question

Please run the following code

`from sympy.solvers import solve`

from sympy import Symbol

x = Symbol('x')

R2 = solve(-109*x**5/3870720+4157*x**4/1935360-3607*x**3/69120+23069*x**2/60480+5491*x/2520+38-67,x)

print R2

The output of the code is

[2*CRootOf(109*x**5 - 4157*x**4 + 50498*x**3 - 184552*x**2 -

527136*x + 3507840, 0), 2*CRootOf(109*x**5 - 4157*x**4 + 50498*x**3

- 184552*x**2 - 527136*x + 3507840, 1), 2*CRootOf(109*x**5 - 4157*x**4 + 50498*x**3 - 184552*x**2 - 527136*x + 3507840, 2),

2*CRootOf(109*x**5 - 4157*x**4 + 50498*x**3 - 184552*x**2 -

527136*x + 3507840, 3), 2*CRootOf(109*x**5 - 4157*x**4 + 50498*x**3

- 184552*x**2 - 527136*x + 3507840, 4)]

Can someone explain what the answer represent and how to get the output in conventional form i.e. say if the answer is

`0.1,0.2,0.3,0.1,0.4`

`[0.1,0.2,0.3,0.1,0.4]`

Answer Source

To get numerical approximations in an answer, you can use N(). Since you have multiple solutions, you can loop through the list. I have used an easier euquation since yours takes a while ...

Try this:

```
from sympy.solvers import solve
from sympy import Symbol, N
x = Symbol('x')
#R2 = solve(-109*x**5/3870720+4157*x**4/1935360-3607*x**3/69120+23069*x**2/60480+5491*x/2520+38-67,x)
R2 = solve(x**2+2*x-4,x)
print R2
print [N(solution) for solution in R2]
```