# Why SymPy Calculate Integral so Long and Unable to get the simple result?

Hi all,

I try this code:

import sympy as sy

x = sy.Symbol("x")

def f(x):
return ((x**6) + 2)/ (8*x ** 2)

def fd(x):
return sy.simplify(sy.diff(f(x), x))

def vx(x):
return 2*np.pi*(f(x)*((1 + (fd(x) ** 2))**(1/2)))
s
vx = sy.simplify(sy.integrate(vx(x), (x, 1, 3)))



the answer is not even simple:

0.785398163397448*Integral((x2 + 1)1.0(x4 - x2 + 1)1.0/x5.0, (x, 1, 3)) + 0.392699081698724*Integral(x1.0*(x2 + 1)1.0(x4 - x**2 + 1)1.0, (x, 1, 3))

I want to calculate the definite integral to find the surface area of this curve $\frac{x^{6} + 2}{8x^{2}}$ revolved about x-axis with $1 \le x \le 3$,

You may get help for sympy here, but if not then look at the support page for sympy.

https://www.sympy.org/en/support.html

Do you mean this?

We can do that with Sympy too, in just five lines of code.

import sympy as sy
x = sy.Symbol("x")

def f(x):
return (x**6 + 2)/(8*x**2)

print(sy.integrate(f(x), (x, 1, 3)))


This prints 373/60 which matches what Wolfram Alpha says.

1 Like

I was not clear enough, I want to integrate to obtain the surface area function, not just the curve (x**6 + 2)/(8*x**2)

the curve will be revolved about x-axis then the formula for the surface area is:

A = 2 π ∫ f(x) [sqrt{1 + f'(x)}] dx

the integral is from a to b (1 to 3).

I use this code:

import sympy as sy
x = sy.Symbol("x")

def f(x):
return (x**6 + 2)/(8*x**2)

def fd(x):
return sy.simplify(sy.diff(f(x), x))

def vx(x):
return f(x)*((1 + (fd(x) ** 2))**(1/2))



Calling this:

sy.simplify(sy.integrate(vx(x), (x, 1, 3)))



I think the problem here is using **(1/2) instead of sympy.sqrt. 1/2 becomes a float before Sympy can get its hands on it.