Why can't sympy calculate a fractional power formula like (6-x * x) ** (1.5)?

I used sympy to compute some integral as follows.

#Calculate Calculus import sympy x = sympy.Symbol('x') f = (6-x*x)**(1.5) f.integrate() 

This will fail and throw excepiton like:

 ValueError: gamma function pole 

It works fine if I just use an integer as power num

 f = (6-x*x)**(2) #result: x**5/5 - 4*x**3 + 36*x 
+5
source share
2 answers

My guess is that expression 1.5 considered a floating point, which is inaccurate. Instead, you will need a symbolic (exact) representation. (I would suggest that if you were after the computational integral, then a floating point would probably be good, as a rule, as the mathematical library supporting the computational integral, as a rule, use the integral approximation method to calculate the integral.) If you need to do arbitrary rational exponents, consider using sympy.Rational . Here is a relevant answer to StackOverflow that seems to support this. I think the documentation for sympy.Rational here . You can try this modified code here :

 #Calculate Calculus import sympy frac = sympy.Rational x = sympy.Symbol('x') f = (6-x*x)**(frac('1.5')) f.integrate() 
+7
source

The previous answer is right, I just post my final result here

 import sympy frac = sympy.Rational x = sympy.symbols('x') f1 = (x+3)/(6-x**2)**(frac('1.5')) f1.integrate() 
+2
source

All Articles