回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>在我的研究中,我在分段函数中找不到任何与关系值相关的例子。虽然我使用<em>uni_dis</em>方法收到了<em>lower</em>和<em>upper</em>值,但我仍在将这些值转换为分段函数的过程中陷入困境。原因是什么</p>
<pre><code>from sympy import Symbol, Piecewise
import sympy as sym
import sympy.plotting as syp
import math
a = Symbol('a')
b = Symbol('b')
x = Symbol('x')
function = 1 / abs(a-b)
def uni_dis(lower, upper):
if lower > upper:
lower, upper = upper, lower
uniform = Piecewise((0, x < lower), (0, x > upper), (function.subs({a:lower, b:upper}), x >= lower and x <= upper))
syp.plot(uniform.subs((x,-10,10), title="uni_dis"))
uni_dis(231, 675)
</code></pre>
<p>我的错误消息如下:</p>
<pre><code>TypeError Traceback (most recent call last)
<ipython-input-3-c28135b22fc4> in <module>
----> 1 uni_dis(231, 675)
<ipython-input-2-e4a205990c2a> in uni_dis(lower, upper)
2 if lower > upper:
3 lower, upper = upper, lower
----> 4 uniform = Piecewise((0, x < lower), (0, x > upper), (function.subs({a:lower, b:upper}), x >= lower and x <= upper))
5 syp.plot(uniform.subs((x,-10,10), title="uni_dis"))
C:\ProgramData\Anaconda3\lib\site-packages\sympy\core\relational.py in __nonzero__(self)
374
375 def __nonzero__(self):
--> 376 raise TypeError("cannot determine truth value of Relational")
377
378 __bool__ = __nonzero__
TypeError: cannot determine truth value of Relational
</code></pre>