如何从Symphy中的NotImplementedError获取值?

2024-04-24 01:25:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用以下代码:

from sympy.solvers import solve
from sympy import Symbol

x = Symbol('x')

function = input("Insert function: ")

def gx(function,x):
    return solve(function,x,dict=True)

print(gx(function,x))

当我写cos(x)+x时,我得到这个错误消息:

Traceback (most recent call last):
  File "/home/raulpenate/Documents/pyhton/MetodosNumericos/Tareas/testing.py", line 11, in <module>
    print(gx(function,x))
  File "/home/raulpenate/Documents/pyhton/MetodosNumericos/Tareas/testing.py", line 9, in gx
    return solve(function,x)
  File "/home/raulpenate/.local/lib/python3.9/site-packages/sympy/solvers/solvers.py", line 1095, in solve
    solution = _solve(f[0], *symbols, **flags)
  File "/home/raulpenate/.local/lib/python3.9/site-packages/sympy/solvers/solvers.py", line 1714, in _solve
    raise NotImplementedError('\n'.join([msg, not_impl_msg % f]))
NotImplementedError: multiple generators [x, cos(x)]
No algorithms are implemented to solve equation x + cos(x)

我想从

NotImplementedError: multiple generators [x, cos(x)]

特别是cos(x),我如何从那里得到那个值?。我在documentation中找不到那个部分


Tags: infrompyimporthomelinefunctioncos