如何在Sympy解析器中使用限制和积分
我想知道如何评估Sympy Parser中的操作方程( sympy.Series.limit函数),例如root,limit或积分。
from sympy.parsing.sympy_parser import parse_expr
temp = parse_expr("limit(1/x, x, 0, +)", transformations='all')
Traceback (most recent call last):
File "c:\Users\asdf\AppData\Local\Programs\Python\Python310\Lib\site-packages\data_manage\test.py", line 70, in <module> parse = parse_expr("limit(1/x, x, 0, +)", transformations='all')
File "C:\Users\asdf\AppData\Local\Programs\Python\Python310\lib\site-packages\sympy\parsing\sympy_parser.py", line 1105, in parse_expr
raise e from ValueError(f"Error from parse_expr with transformed code: {code!r}")
File "C:\Users\asdf\AppData\Local\Programs\Python\Python310\lib\site-packages\sympy\parsing\sympy_parser.py", line 1096, in parse_expr
rv = eval_expr(code, local_dict, global_dict)
File "C:\Users\asdf\AppData\Local\Programs\Python\Python310\lib\site-packages\sympy\parsing\sympy_parser.py", line 915,
in eval_expr
expr = eval(
File "<string>", line 1
limit (Integer (1 )/Symbol ('x' ),Symbol ('x' ),Integer (0 ),+)
^
SyntaxError: invalid syntax
I want to know how to evaluates equations with operations in sympy parser(NOT with sympy.series.Limit Function), such as root, limit, or integral.
from sympy.parsing.sympy_parser import parse_expr
temp = parse_expr("limit(1/x, x, 0, +)", transformations='all')
Traceback (most recent call last):
File "c:\Users\asdf\AppData\Local\Programs\Python\Python310\Lib\site-packages\data_manage\test.py", line 70, in <module> parse = parse_expr("limit(1/x, x, 0, +)", transformations='all')
File "C:\Users\asdf\AppData\Local\Programs\Python\Python310\lib\site-packages\sympy\parsing\sympy_parser.py", line 1105, in parse_expr
raise e from ValueError(f"Error from parse_expr with transformed code: {code!r}")
File "C:\Users\asdf\AppData\Local\Programs\Python\Python310\lib\site-packages\sympy\parsing\sympy_parser.py", line 1096, in parse_expr
rv = eval_expr(code, local_dict, global_dict)
File "C:\Users\asdf\AppData\Local\Programs\Python\Python310\lib\site-packages\sympy\parsing\sympy_parser.py", line 915,
in eval_expr
expr = eval(
File "<string>", line 1
limit (Integer (1 )/Symbol ('x' ),Symbol ('x' ),Integer (0 ),+)
^
SyntaxError: invalid syntax
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将极限方向包裹到字符串文字中:
You need to wrap the limit direction into a string literal: