我正在尝试使用python在以下等式中求解x;
20 = 3^x - x - 4
我尝试使用sympy resolve(),但是它没有输出求解x的结果,而是输出了另一个方程。
当前代码:
x = Symbol('x', integer = True)
eqn = Eq(3**x - x - 4, 20)
r = solve(eqn)
预期输出:
r = −24, 3
实际输出:
[-24 - LambertW(-log(3)/282429536481)/log(3), -24 - LambertW(-log(3)/282429536481, -1)/log(3)]
答案 0 :(得分:-1)
Sympy在这里给出正确的答案,答案恰好非常接近-24和3。例如,Wolfram Alpha说答案是-23.99999999999645929383851407736751424572557264463826050688997713695590353717193719618212151198215945和3,请参见https://www.wolframalpha.com/input/?i=solve+3%5Ex+-+x+-+4+%3D+20。确实,sympy同意:
>>> sympy.N(r[0], 100)
-23.99999999999645929383851407736751424572557264463826050688997713695590353717193719618212151198215945
>>> sympy.N(r[1], 100)
3.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000