I was doing a numerical integration where instead of using
scipy.integrate.dblquad
I tried to build the double integral directly using
scipy.integrate.quad
From camz's answer: https://stackoverflow.com/a/30786163/11141816
a=1
b=2
def integrand(theta, t):
return sin(t)*sin(theta);
def theta_integral(t):
# Note scipy will pass args as the second argument
return integrate.quad(integrand, b-a, t , args=(t))[0]
integrate.quad(theta_integral, b-a,b+a )
However, the part where it was confusing was how the args was passed through the function. For example, in the post args=(t)
was pass through to the second argument t
of the function integrand automatically, not the first argument theta
, where in the scipy document https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.quad.html the only reference was
args: tuple, optional
Extra arguments to pass to func.
and in fact their arguments had a comma ,
to be args=(1,)
, instead of args=(1)
directly.
What if I decide to pass several variables, i.e.
def integrand(theta, t,a,b):
return sin(t)*sin(theta)*a*b;
how would I know which args(t,a,b)
or args(t,a,b,)
were the correct args()
for the function?
How to pass args()
to integrate.quad in scipy?