Complete the code to import the function for numerical integration.
from scipy.integrate import [1]
The quad function from scipy.integrate is used for single integrals.
Complete the code to define the function to integrate: f(x) = x^2.
def f(x): return x[1]2
In Python, ** is used for exponentiation, so x**2 means x squared.
Fix the error in the integration call to integrate f from 0 to 1.
result, error = quad([1], 0, 1)
The function quad expects the function name without parentheses to pass it as an argument.
Fill both blanks to print the integral result and the estimated error.
print('Integral:', [1]) print('Error estimate:', [2])
The quad function returns a tuple: (result, error). Use these variables directly.
Fill all three blanks to compute and print the integral of sin(x) from 0 to pi.
import numpy as np from scipy.integrate import [1] result, error = [2](np.[3], 0, np.pi) print(result)
We import quad to integrate, then call quad on np.sin from 0 to π.
