Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the function for numerical integration.
SciPy
from scipy.integrate import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'integrate' which is the module, not the function.
Using 'solve' which is unrelated to integration.
Using 'diff' which is for differentiation.
✗ Incorrect
The quad function from scipy.integrate is used for single integrals.
2fill in blank
mediumComplete the code to define the function to integrate: f(x) = x^2.
SciPy
def f(x): return x[1]2
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '^' which is bitwise XOR, not power.
Using '*' which is multiplication, not power.
✗ Incorrect
In Python, ** is used for exponentiation, so x**2 means x squared.
3fill in blank
hardFix the error in the integration call to integrate f from 0 to 1.
SciPy
result, error = quad([1], 0, 1)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the function with parentheses inside quad.
Passing a function call instead of the function object.
✗ Incorrect
The function quad expects the function name without parentheses to pass it as an argument.
4fill in blank
hardFill both blanks to print the integral result and the estimated error.
SciPy
print('Integral:', [1]) print('Error estimate:', [2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to index result or error as if they were lists.
Using wrong variable names.
✗ Incorrect
The quad function returns a tuple: (result, error). Use these variables directly.
5fill in blank
hardFill all three blanks to compute and print the integral of sin(x) from 0 to pi.
SciPy
import numpy as np from scipy.integrate import [1] result, error = [2](np.[3], 0, np.pi) print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using cosine instead of sine.
Using different names for import and call.
✗ Incorrect
We import quad to integrate, then call quad on np.sin from 0 to π.