Skip to content Skip to sidebar Skip to footer

Can Scipy.integrate.fixed_quad Compute Integral With Functional Boundaries?

I would like to numerically integrate function over a triangle similarly as import scipy.integrate as integrate inside = lambda x: integrate.quad(lambda x,y: 1, 0, x, args=(x))[0]

Solution 1:

The problem is your definition of args, args=(x). It should be passed as a tuple, so you need to add an additional comma to make it a tuple:

inside = lambda x: integrate.fixed_quad(lambda x,y: 1, 0, x, args=(x,), n=5)

Then

inside(5)

yields

(5.0, None)

The line

integrate.quad(lambda x,y: 1, 0, x, args=(x))[0]

works as in quad it is checked whether args is a tuple; if not it is converted (directly taken from the source code):

if not isinstance(args, tuple):
        args = (args,)

In fixed_quad that is not the case and that's why you received the error in one but not both cases.


Post a Comment for "Can Scipy.integrate.fixed_quad Compute Integral With Functional Boundaries?"