Python Forum
Symbolic integration with SymPy thrown an error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Symbolic integration with SymPy thrown an error
#1
I ran into a problem with SymPy.jl for symbolic integration,

using SymPy
m = symbols(“m”, integer=true)
n = symbols(“n”, integer=true)
x = symbols(“x”, integer=true)
integrate(diff(x^4,(x,2)),x)
The output is 4*x^3

When I actually need the results of this expression:integrate(diff(x^m,(x,n)),x)

An error is thrown:

Error:
ERROR: PyError ($(Expr(:escape, :(ccall(#= /home/.julia/packages/PyCall/7a7w0/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'TypeError'> TypeError('\nCannot give expansion for symbolic count. If you just want a list of\nall variables of differentiation, use _wrt_variables.') File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/integrals/integrals.py", line 1566, in integrate return integral.doit(**doit_flags) File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/integrals/integrals.py", line 613, in doit antideriv = self._eval_integral( File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/integrals/integrals.py", line 1098, in _eval_integral h = meijerint_indefinite(g, x) File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/integrals/meijerint.py", line 1672, in meijerint_indefinite for a in sorted(_find_splitting_points(f, x) | {S.Zero}, key=default_sort_key): File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/integrals/meijerint.py", line 424, in _find_splitting_points compute_innermost(expr, innermost) File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/integrals/meijerint.py", line 415, in compute_innermost m = expr.match(p*x + q) File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/core/basic.py", line 1702, in match m = canonical(pattern).matches(canonical(self), old=old) File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/core/add.py", line 553, in matches return self._matches_commutative(expr, repl_dict, old) File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/core/operations.py", line 336, in _matches_commutative expr = collect(expr, free) File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/simplify/radsimp.py", line 391, in collect terms = [parse_term(i) for i in args] File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/simplify/radsimp.py", line 391, in <listcomp> terms = [parse_term(i) for i in args] File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/simplify/radsimp.py", line 281, in parse_term sexpr, deriv = parse_derivative(expr) File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/simplify/radsimp.py", line 211, in parse_derivative expr, sym, order = deriv.expr, deriv.variables[0], 1 File "/home/.julia/conda/3/lib/python3.9/site-packages/sympy/core/function.py", line 1664, in variables raise TypeError(filldedent(''' Stacktrace: [1] pyerr_check @ ~/.julia/packages/PyCall/7a7w0/src/exception.jl:62 [inlined] [2] pyerr_check @ ~/.julia/packages/PyCall/7a7w0/src/exception.jl:66 [inlined] [3] _handle_error(msg::String) @ PyCall ~/.julia/packages/PyCall/7a7w0/src/exception.jl:83 [4] macro expansion @ ~/.julia/packages/PyCall/7a7w0/src/exception.jl:97 [inlined] [5] #107 @ ~/.julia/packages/PyCall/7a7w0/src/pyfncall.jl:43 [inlined] [6] disable_sigint @ ./c.jl:458 [inlined] [7] __pycall! @ ~/.julia/packages/PyCall/7a7w0/src/pyfncall.jl:42 [inlined] [8] _pycall!(ret::PyCall.PyObject, o::PyCall.PyObject, args::Tuple{Sym, Sym}, nargs::Int64, kw::Ptr{Nothing}) @ PyCall ~/.julia/packages/PyCall/7a7w0/src/pyfncall.jl:29 [9] _pycall!(ret::PyCall.PyObject, o::PyCall.PyObject, args::Tuple{Sym, Sym}, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ PyCall ~/.julia/packages/PyCall/7a7w0/src/pyfncall.jl:11 [10] (::PyCall.PyObject)(::Sym, ::Vararg{Sym}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ PyCall ~/.julia/packages/PyCall/7a7w0/src/pyfncall.jl:86 [11] (::PyCall.PyObject)(::Sym, ::Vararg{Sym}) @ PyCall ~/.julia/packages/PyCall/7a7w0/src/pyfncall.jl:86 [12] integrate(ex::Sym, args::Sym; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ SymPy ~/.julia/packages/SymPy/ycPbL/src/importexport.jl:102 [13] integrate(ex::Sym, args::Sym) @ SymPy ~/.julia/packages/SymPy/ycPbL/src/importexport.jl:102 [14] top-level scope @ REPL[6]:1
It looks like the problem is on the symbol n. I can’t find a solution, so I hope you guys can help me
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Integration of Python with MatDeck software babicmatpy 4 4,164 Jun-30-2019, 06:34 PM
Last Post: babicmatpy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020