4

I used sympy to calculate 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
Pythoner
  • 5,265
  • 5
  • 33
  • 49

2 Answers2

7

My guess is a 1.5 expression is treated as a floating point, which is imprecise. You'd want a symbolic (exact) representation, instead. (I would guess if you were after a computational integral a floating point would probably be okay, generally, as a math library that supports a computational integral would typically use an integral approximation method to compute the integral.) If you need to do arbitrary rational exponents, consider using sympy.Rational. Here's a relevant answer on StackOverflow that seems to support this. I think the documentation for sympy.Rational is 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() 
Community
  • 1
  • 1
Jesus is Lord
  • 14,971
  • 11
  • 66
  • 97
  • still raise error on my own machine. but works on that app. – Pythoner May 04 '16 at 04:29
  • @PythonNewHand I suspect that's related to your environment, then. My advice would be to check your version of Python vs. Sympy (make sure they're compatible with each other and your OS/computer). Also try those exact versions on a different computer and/or OS to isolate the issue. I don't know much about Python, but it could be related to things like configuration/installation such as PATH variables or something. Since this works online, your environment issues would constitute a different question - probably better asked as a separate question, but I tried my best, here. Good luck! – Jesus is Lord May 04 '16 at 04:37
  • @PythonNewHand I confirm that changing to `sympy.Rational('1.5')` leads to correct result in SymPy 1.0. An upgrade may be in order. –  May 04 '16 at 04:54
1

The previous answer is right, I'm just posting my final result here

import sympy
frac = sympy.Rational
x = sympy.symbols('x')
f1 = (x+3)/(6-x**2)**(frac('1.5'))
f1.integrate()
Pythoner
  • 5,265
  • 5
  • 33
  • 49