0
0
SciPydata~20 mins

Triple integral (tplquad) in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
šŸŽ–ļø
Triple Integral Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ā“ Predict Output
intermediate
2:00remaining
Output of a triple integral using tplquad
What is the output of this code that calculates the triple integral of f(x,y,z) = x + y + z over the cube where x, y, z range from 0 to 1?
SciPy
from scipy.integrate import tplquad

func = lambda z, y, x: x + y + z
result, error = tplquad(func, 0, 1, lambda x: 0, lambda x: 1, lambda x, y: 0, lambda x, y: 1)
print(round(result, 3))
A2.0
B3.0
C0.5
D1.5
Attempts:
2 left
šŸ’” Hint
Remember the integral of x, y, or z from 0 to 1 is 0.5 each, and the integral sums over all three variables.
ā“ data_output
intermediate
1:30remaining
Number of items in the result tuple from tplquad
After running tplquad, how many items are in the returned result tuple?
SciPy
from scipy.integrate import tplquad

func = lambda z, y, x: x*y*z
result = tplquad(func, 0, 1, lambda x: 0, lambda x: 1, lambda x, y: 0, lambda x, y: 1)
print(len(result))
A2
B1
C3
D4
Attempts:
2 left
šŸ’” Hint
tplquad returns the integral value and an estimate of the error.
šŸ”§ Debug
advanced
2:00remaining
Identify the error in this tplquad usage
What error does this code raise when trying to compute the triple integral of f(x,y,z) = x*y*z with incorrect bounds?
SciPy
from scipy.integrate import tplquad

func = lambda z, y, x: x*y*z
result = tplquad(func, 0, 1, lambda x: 1, lambda x: 0, lambda x, y: 0, lambda x, y: 1)
print(result[0])
ATypeError: 'int' object is not callable
BSyntaxError: invalid syntax
CValueError: Integration limits are not in ascending order
DNo error, outputs a float
Attempts:
2 left
šŸ’” Hint
Check the order of the lower and upper bounds in the lambda functions.
🧠 Conceptual
advanced
1:30remaining
Understanding the order of variables in tplquad
In the function passed to tplquad, what is the order of variables for the integrand function?
Ay, z, x
Bz, y, x
Cx, y, z
Dx, z, y
Attempts:
2 left
šŸ’” Hint
Check the scipy documentation for tplquad variable order in the integrand.
šŸš€ Application
expert
3:00remaining
Calculate the volume of a tetrahedron using tplquad
Use tplquad to calculate the volume of the tetrahedron bounded by x, y, z ≄ 0 and x + y + z ≤ 1. What is the integral result?
SciPy
from scipy.integrate import tplquad

func = lambda z, y, x: 1
result, error = tplquad(func, 0, 1, lambda x: 0, lambda x: 1 - x, lambda x, y: 0, lambda x, y: 1 - x - y)
print(round(result, 3))
A0.167
B0.333
C0.500
D1.000
Attempts:
2 left
šŸ’” Hint
The volume of this tetrahedron is 1/6, which is approximately 0.167.