Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Romberg integration function from scipy.
SciPy
from scipy.integrate import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing
quad instead of romberg.Using integration functions unrelated to Romberg.
✗ Incorrect
The romberg function is used for Romberg integration in scipy.
2fill in blank
mediumComplete the code to define the function f(x) = x^2 for integration.
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
* instead of ** for power.Using
+ or // which are incorrect here.✗ Incorrect
The ** operator is used for exponentiation in Python.
3fill in blank
hardFix the error in calling romberg to integrate f from 0 to 1.
SciPy
result = romberg(f, [1], 1)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the limits or passing the function instead of a limit.
Using 1 as the first limit which is the upper limit.
✗ Incorrect
The integration lower limit is 0, so it must be the first argument after the function.
4fill in blank
hardFill both blanks to compute Romberg integration of sin(x) from 0 to pi.
SciPy
import numpy as np result = romberg(np.[1], 0, [2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using cosine instead of sine.
Using
e instead of pi as upper limit.✗ Incorrect
We integrate sin from 0 to pi (np.pi).
5fill in blank
hardFill all three blanks to create a dictionary of Romberg results for functions over [0, 1].
SciPy
functions = {'square': lambda x: x[1]2, 'cube': lambda x: x[2]3}
results = {name: romberg(func, 0, 1) for name, func in functions.items() if func(0) == [3] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication
* instead of exponentiation **.Checking if function(0) equals 1 instead of 0.
✗ Incorrect
Use ** for powers and check if function value at 0 equals 0.