Code Explanation:
Importing the integration module:
import scipy.integrate as spi
You are importing the integrate module from SciPy and aliasing it as spi.
Defining the function to integrate:
def integrand(x):
return x ** 2
This is the function
f(x)=x 2
which you want to integrate.
Calling quad to perform definite integration:
result, error = spi.quad(integrand, 0, 1)
spi.quad performs numerical integration.
It integrates integrand(x) from x = 0 to x = 1.
It returns:
result: The value of the integral.
error: An estimate of the absolute error.
Printing the result:
print(result)
Output:
0.33333333333333337
.png)

0 Comments:
Post a Comment