Challenge - 5 Problems
Simpson's Rule Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Simpson's rule integration with simple function
What is the output of this code that uses Simpson's rule to integrate f(x) = x^2 from 0 to 2 with 5 points?
SciPy
import numpy as np from scipy.integrate import simpson x = np.linspace(0, 2, 5) y = x**2 result = simpson(y, x) print(round(result, 4))
Attempts:
2 left
💡 Hint
Recall the exact integral of x^2 from 0 to 2 is 8/3 ≈ 2.6667. Simpson's rule should approximate closely.
✗ Incorrect
Simpson's rule approximates the integral of x^2 from 0 to 2 as about 2.6667, which matches the exact value 8/3.
❓ data_output
intermediate1:30remaining
Number of intervals used in Simpson's rule with uneven spacing
Given unevenly spaced points x and function values y, how many intervals does scipy.integrate.simpson use internally for integration?
SciPy
import numpy as np from scipy.integrate import simpson x = np.array([0, 1, 1.5, 2.5, 3]) y = np.sin(x) result = simpson(y, x) intervals = len(x) - 1 print(intervals)
Attempts:
2 left
💡 Hint
Intervals are the spaces between points, so count points minus one.
✗ Incorrect
Simpson's rule uses intervals between points, so with 5 points, there are 4 intervals.
🔧 Debug
advanced2:00remaining
Identify the error in Simpson's rule usage
What error does this code raise when trying to integrate y = x^3 over 0 to 3 with 4 points using simpson?
SciPy
import numpy as np from scipy.integrate import simpson x = np.linspace(0, 3, 4) y = x**3 result = simpson(y, x) print(result)
Attempts:
2 left
💡 Hint
Simpson's rule needs an odd number of points to work correctly.
✗ Incorrect
Simpson's rule in scipy requires an odd number of samples; 4 points is even, so it raises a ValueError.
🚀 Application
advanced1:30remaining
Choosing the correct Simpson's rule call for equally spaced data
You have y values of a function sampled at equal intervals of 0.1 seconds. Which simpson call correctly computes the integral over time?
Attempts:
2 left
💡 Hint
When spacing is uniform, use dx parameter for efficiency.
✗ Incorrect
Using dx=0.1 tells simpson the spacing between points, which is correct for equally spaced data.
🧠 Conceptual
expert2:30remaining
Why does Simpson's rule require an odd number of points?
Why must the number of sample points be odd when using Simpson's rule for numerical integration?
Attempts:
2 left
💡 Hint
Think about how parabolas are fit between points.
✗ Incorrect
Simpson's rule approximates the function by fitting parabolas over pairs of intervals, which requires an odd number of points.