xzt
xzt

Reputation: 111

TypeError: cannot determine truth value of Relational when using sympy.solver

I want to numerically solve the equation

beta.ppf(x,a,b)-c=0

where a,b,c are known constants. When I tried

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)

It returned me

TypeError: cannot determine truth value of Relational

How can I fix it?

Upvotes: 0

Views: 3578

Answers (1)

Stelios
Stelios

Reputation: 5521

Scipy.optimize (check section: "Root finding") provides numerous functions for numerically solving equations.

For the following example, I will use the newton 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 a, b, and c.

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))

0.6399999999999999

Upvotes: 1

Related Questions