0
0
SciPydata~10 mins

Trapezoidal rule (trapezoid) in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the trapezoidal rule function from scipy.

SciPy
from scipy.integrate import [1]
Drag options to blanks, or click blank then click option'
Atrapz
Bquad
Csimps
Ddblquad
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'quad' which is for adaptive quadrature, not trapezoidal rule.
Using 'simps' which is Simpson's rule, not trapezoidal.
2fill in blank
medium

Complete the code to calculate the integral of y with respect to x using the trapezoidal rule.

SciPy
result = trapz([1], x)
Drag options to blanks, or click blank then click option'
Ay
Bintegral
Cresult
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Passing x as the first argument instead of y.
Passing the result variable as input.
3fill in blank
hard

Fix the error in the code to correctly compute the integral using the trapezoidal rule.

SciPy
integral = trapz(y, [1])
Drag options to blanks, or click blank then click option'
Aintegral
Bx
Cresult
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Passing y as both arguments.
Passing the result variable instead of x.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each x to its y value only if y is greater than 0.

SciPy
{x: y for x, y in zip([1], [2]) if y > 0}
Drag options to blanks, or click blank then click option'
Ax_values
By_values
Cx
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping x and y in the zip function.
Using variable names not defined in the code.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps the uppercase string of each x to its y value only if y is greater than 0.

SciPy
{ [1]: [2] for x, y in zip(x_values, y_values) if [3] > 0 }
Drag options to blanks, or click blank then click option'
Ax.upper()
By
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using x instead of x.upper() as key.
Checking x > 0 instead of y > 0.