TypeError: cannot determine truth value of Relational when using sympy.solver
<p>I want to numerically solve the equation </p>

<blockquote>
  <p>beta.ppf(x,a,b)-c=0</p>
</blockquote>

<p>where a,b,c are known constants. When I tried</p>

<pre><code>from sympy.solvers import solve
from sympy import Symbol 
from scipy.stats import beta
x=Symbol('x')
solve(beta.ppf(x,a,b)-c,x)
</code></pre>

<p>It returned me</p>

<blockquote>
  <p>TypeError: cannot determine truth value of Relational</p>
</blockquote>

<p>How can I fix it?</p>

<p><a href="http://docs.scipy.org/doc/scipy/reference/optimize.html#root-finding" rel="nofollow">Scipy.optimize</a> (check section: "Root finding") provides numerous functions for numerically solving equations. </p>

<p>For the following example, I will use the <code>newton</code> function (the other available solvers might be more appropriate for your problem - you should also check them out). I have used arbitrary numerical values for <code>a</code>, <code>b</code>, and <code>c</code>. </p>

<pre><code>from scipy.stats import beta
from scipy.optimize import newton

a = 1
b = 2
c = 0.4

def f(x, a, b, c):
    return beta.ppf(x, a, b) - c

newton(f, x0 = 0.2, args = (a,b,c))
</code></pre>

<blockquote>
  <p><code>0.6399999999999999</code></p>
</blockquote>

python scipy