1
sympy로 Python에서 일부 미적분을 수행하려고하는데 문제가 생겼고 근본을 이해하지 못합니다. 나는 Python 3.6과 함께 Anaconda suite, Jupyter Notebook 및 IPython 5.3.0 버전을 사용하고 있습니다.Sympy에서 파생 상품의 통합 기능
내가
from sympy import Funtion, symbols, integrate
from IPython.display import display
t, s = symbols('t s')
f = Function('f')
c = Function('c')
는 다음 식을 계산 writte 경우 예상 (라텍스) 표현이 표시
display(f(t, s))
display(c(t, s))
display(f(c(t, s)))
display(f(c(t, s), c(t, s).diff(t)))
display(integrate(f(t, s), t))
display(integrate(f(c(t, s)), t))
display(integrate(f(c(t, s).diff(t)), t))
display(integrate(f(c(t, s),c(s,t)), t))
(그들은 실패 부분의 요소가 될 것입니다). 나는 유도 및 여러 변수의 통합을 처리 할 수 있는지 볼 수 있지만 내가
display(integrate(f(c(t, s), c(t, s).diff(t)), t))
에로,을 togheter 몇 가지를 넣어하려고 할 때 다음과 같은 오류가
한편Can't calculate 1st derivative wrt Derivative(_x1, t).
발생
display(integrate(f(c(t,s), c(t,s).diff(t)), s))
올바른 출력을 표시합니다. 어떻게하면이 문제를 해결할 수 있을까요?
사전에편집을 주셔서 감사합니다 : .doit()가 도움이되지 않았습니다.
오류가 난 단지를 구성하고 을 (를 A doit()
을 수행하지 않은 경우)을 계산하지 시도를 수행하는 적분을 표시 Integral
을 사용
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-21-66abd1a98aff> in <module>()
11 display(integrate(f(c(t,s).diff(t)), t))
12 display(integrate(f(c(t,s), c(s,t)), t))
---> 13 display(integrate(f(c(t,s), c(t,s).diff(t)), t))
....\Anaconda2\envs\Py3\lib\site-packages\sympy\integrals\integrals.py in integrate(*args, **kwargs)
1278 if isinstance(integral, Integral):
1279 return integral.doit(deep=False, meijerg=meijerg, conds=conds,
-> 1280 risch=risch, manual=manual)
1281 else:
1282 return integral
....\Anaconda2\envs\Py3\lib\site-packages\sympy\integrals\integrals.py in doit(self, **hints)
484 function, xab[0],
485 meijerg=meijerg1, risch=risch, manual=manual,
--> 486 conds=conds)
487 if antideriv is None and meijerg1 is True:
488 ret = try_meijerg(function, xab)
....\Anaconda2\envs\Py3\lib\site-packages\sympy\integrals\integrals.py in _eval_integral(self, f, x, meijerg, risch, manual, conds)
885 try:
886 if conds == 'piecewise':
--> 887 h = heurisch_wrapper(g, x, hints=[])
888 else:
889 h = heurisch(g, x, hints=[])
....\Anaconda2\envs\Py3\lib\site-packages\sympy\integrals\heurisch.py in heurisch_wrapper(f, x, rewrite, hints, mappings, retries, degree_offset, unnecessary_permutations)
128
129 res = heurisch(f, x, rewrite, hints, mappings, retries, degree_offset,
--> 130 unnecessary_permutations)
131 if not isinstance(res, Basic):
132 return res
....\Anaconda2\envs\Py3\lib\site-packages\sympy\integrals\heurisch.py in heurisch(f, x, rewrite, hints, mappings, retries, degree_offset, unnecessary_permutations)
672 else:
673 if retries >= 0:
--> 674 result = heurisch(f, x, mappings=mappings, rewrite=rewrite, hints=hints, retries=retries - 1, unnecessary_permutations=unnecessary_permutations)
675
676 if result is not None:
....\Anaconda2\envs\Py3\lib\site-packages\sympy\integrals\heurisch.py in heurisch(f, x, rewrite, hints, mappings, retries, degree_offset, unnecessary_permutations)
672 else:
673 if retries >= 0:
--> 674 result = heurisch(f, x, mappings=mappings, rewrite=rewrite, hints=hints, retries=retries - 1, unnecessary_permutations=unnecessary_permutations)
675
676 if result is not None:
....\Anaconda2\envs\Py3\lib\site-packages\sympy\integrals\heurisch.py in heurisch(f, x, rewrite, hints, mappings, retries, degree_offset, unnecessary_permutations)
672 else:
673 if retries >= 0:
--> 674 result = heurisch(f, x, mappings=mappings, rewrite=rewrite, hints=hints, retries=retries - 1, unnecessary_permutations=unnecessary_permutations)
675
676 if result is not None:
....\Anaconda2\envs\Py3\lib\site-packages\sympy\integrals\heurisch.py in heurisch(f, x, rewrite, hints, mappings, retries, degree_offset, unnecessary_permutations)
451 mapping = list(mapping)
452 mapping = mapping + unnecessary_permutations
--> 453 diffs = [ _substitute(dcache.get_diff(g)) for g in terms ]
454 denoms = [ g.as_numer_denom()[1] for g in diffs ]
455 if all(h.is_polynomial(*V) for h in denoms) and _substitute(f).is_rational_function(*V):
....\Anaconda2\envs\Py3\lib\site-packages\sympy\integrals\heurisch.py in <listcomp>(.0)
451 mapping = list(mapping)
452 mapping = mapping + unnecessary_permutations
--> 453 diffs = [ _substitute(dcache.get_diff(g)) for g in terms ]
454 denoms = [ g.as_numer_denom()[1] for g in diffs ]
455 if all(h.is_polynomial(*V) for h in denoms) and _substitute(f).is_rational_function(*V):
....\Anaconda2\envs\Py3\lib\site-packages\sympy\integrals\heurisch.py in _substitute(expr)
446
447 def _substitute(expr):
--> 448 return expr.subs(mapping)
449
450 for mapping in mappings:
....\Anaconda2\envs\Py3\lib\site-packages\sympy\core\basic.py in subs(self, *args, **kwargs)
900 rv = self
901 for old, new in sequence:
--> 902 rv = rv._subs(old, new, **kwargs)
903 if not isinstance(rv, Basic):
904 break
....\Anaconda2\envs\Py3\lib\site-packages\sympy\core\cache.py in wrapper(*args, **kwargs)
91 def wrapper(*args, **kwargs):
92 try:
---> 93 retval = cfunc(*args, **kwargs)
94 except TypeError:
95 retval = func(*args, **kwargs)
....\Anaconda2\envs\Py3\lib\site-packages\sympy\core\basic.py in _subs(self, old, new, **hints)
1014 rv = self._eval_subs(old, new)
1015 if rv is None:
-> 1016 rv = fallback(self, old, new)
1017 return rv
1018
....\Anaconda2\envs\Py3\lib\site-packages\sympy\core\basic.py in fallback(self, old, new)
986 if not hasattr(arg, '_eval_subs'):
987 continue
--> 988 arg = arg._subs(old, new, **hints)
989 if not _aresame(arg, args[i]):
990 hit = True
....\Anaconda2\envs\Py3\lib\site-packages\sympy\core\cache.py in wrapper(*args, **kwargs)
91 def wrapper(*args, **kwargs):
92 try:
---> 93 retval = cfunc(*args, **kwargs)
94 except TypeError:
95 retval = func(*args, **kwargs)
....\Anaconda2\envs\Py3\lib\site-packages\sympy\core\basic.py in _subs(self, old, new, **hints)
1012 return new
1013
-> 1014 rv = self._eval_subs(old, new)
1015 if rv is None:
1016 rv = fallback(self, old, new)
....\Anaconda2\envs\Py3\lib\site-packages\sympy\core\function.py in _eval_subs(self, old, new)
1340 variables = self_vars_front + self_vars
1341 return Derivative(new, *variables)
-> 1342 return Derivative(*(x._subs(old, new) for x in self.args))
1343
1344 def _eval_lseries(self, x, logx):
....\Anaconda2\envs\Py3\lib\site-packages\sympy\core\function.py in __new__(cls, expr, *variables, **assumptions)
1068 ordinal = 'st' if last_digit == 1 else 'nd' if last_digit == 2 else 'rd' if last_digit == 3 else 'th'
1069 raise ValueError(filldedent('''
-> 1070 Can\'t calculate %s%s derivative wrt %s.''' % (count, ordinal, v)))
1071
1072 if all_zero and not count == 0:
ValueError:
Can't calculate 1st derivative wrt Derivative(_x1, t).
그 기능이 있다는 것을 깨닫지 못했습니다. 고맙습니다. 완벽하게 작동했습니다. – iiqof