如何在Sympy解析器中使用限制和积分

发布于 2025-02-09 02:01:39 字数 1225 浏览 1 评论 0原文

我想知道如何评估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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不会写诗 2025-02-16 02:01:39

您需要将极限方向包裹到字符串文字中:

temp = parse_expr("limit(1/x, x, 0, '+')", transformations='all')

You need to wrap the limit direction into a string literal:

temp = parse_expr("limit(1/x, x, 0, '+')", transformations='all')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文