Python sympy module problems

Viewed 48

I met some problems when I using sympy to solve mathematical problems, my code is like this,

eq1=Eq(0, -sympy.sqrt(x**2) + sympy.sqrt((x + 4)**2))
sympy.solve(eq1,x)

the answer for this equation ought to be -2, but I got an empty list instead

1 Answers
eq1=Eq(0, -sympy.sqrt(x**2) + sympy.sqrt((x + 4)**2))
sympy.solveset(eq1,x)

this should work

OUTPUT

{-2}

btw sympy got an exelent website that would have given you the answer, along with a very intuitive shell inside the browser https://docs.sympy.org/latest/tutorial/solvers.html

here is what sympy has to say on the matter:

"Please note that there is another function called solve which can also be used to solve equations. The syntax is solve(equations, variables) However, it is recommended to use solveset instead."

Related