from scipy.integrate import quad
def integrand(a, b):
return a * x ** 2 + b
a = 2
b = 1
I = quad(integrand, 0, 1, args=(a,b))
I
This is my program. When I tried to run it, it was showing error :
integrand () takes 2 positional arguments but 3 were given ....
I didn't understand why it is asking for 3 arguments when there are only two variables, i.e. a
and b
.
Can anyone help me? Can anyone clarify my doubts?
Scipy is the scientific computing module of Python providing in-built functions on a lot of well-known Mathematical functions. The scipy. integrate sub-package provides several integration techniques including an ordinary differential equation integrator.
The quad function returns the two values, in which the first number is the value of integral and the second value is the estimate of the absolute error in the value of integral. Note − Since quad requires the function as the first argument, we cannot directly pass exp as the argument.
Just replace
def integrand(a, b):
by
def integrand(x, a, b):
The problem is that in the function, you use a variable x
but you do not pass the variable x
as an argument to the function. 0
and 1
acts as the limits of the integral but since you are integrating w.r.t. x
, you get this error.
Output
(1.6666666666666667, 1.8503717077085944e-14)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With