a = theta*phi/pi # Suppose this is a huge expression that came out of previous calculations
def doubleIntegral():
def f2(theta):
def f1(phi):
return a
return numerical_integral(f1,0,2*pi)[0]
return numerical_integral(f2,0,pi)

1 answer

In the second example function, you are returning a from the innermost loop, but a is a symbolic expression. In the first example, what you return from the innermost loop is just a number evaluated at theta and phi. What happens if you instead use return a.subs(theta=theta, phi=phi) in the second example?