0
0
SciPydata~10 mins

Double integral (dblquad) in SciPy - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Double integral (dblquad)
Define function f(y,x)
Set integration limits for y
Set integration limits for x
Call dblquad(f, x_lower, x_upper, y_lower(x), y_upper(x))
Compute inner integral over y
Compute outer integral over x
Return total integral and error estimate
The process defines the function and integration limits, then computes the inner integral over y for each x, followed by the outer integral over x, returning the total integral value.
Execution Sample
SciPy
from scipy.integrate import dblquad

f = lambda y, x: x * y
result, error = dblquad(f, 0, 2, lambda x: 0, lambda x: 3)
print(result)
This code calculates the double integral of f(y,x) = x*y over x from 0 to 2 and y from 0 to 3.
Execution Table
StepActionx valueInner integral over yPartial resultNotes
1Start dblquad---Begin integration over x from 0 to 2
2Evaluate inner integral at x=00Integral of 0*y dy from 0 to 3 = 00f(y,0) = 0 for all y
3Evaluate inner integral at x=11Integral of 1*y dy from 0 to 3 = 4.5Partial outer integral accumulatesIntegral y dy = y^2/2 from 0 to 3 = 4.5
4Evaluate inner integral at x=22Integral of 2*y dy from 0 to 3 = 9Partial outer integral accumulatesDouble the previous inner integral value
5Compute outer integral over x--Total integral = 9Integral of inner results over x from 0 to 2
6Return result and error--9.0Integration complete
💡 Integration completes after evaluating inner integrals at sample points and summing over x range
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
x-012-
inner_integral-04.59-
result----9.0
Key Moments - 3 Insights
Why does the function f take arguments in the order (y, x) instead of (x, y)?
In dblquad, the function must be defined as f(y, x) because the integration is done first over y (inner integral), then over x (outer integral). This matches the calling convention shown in the execution_table steps.
How are the limits for y defined as functions of x?
The limits for y are given as functions of x (here constant 0 and 3). This allows flexible integration regions. The execution_table shows these limits used at each x step.
Why do we see partial inner integrals before the final result?
dblquad computes the inner integral over y for each x, then sums these results over x. The execution_table rows 2-4 show these partial inner integrals accumulating to the final total.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the inner integral value at x=1?
A0
B9
C4.5
D3
💡 Hint
Check row 3 in the execution_table under 'Inner integral over y'
At which step does the outer integral complete?
AStep 4
BStep 5
CStep 6
DStep 3
💡 Hint
Look for the step where the total integral is computed over x in the execution_table
If the upper limit for y changed from 3 to 4, how would the inner integral at x=1 change?
AIt would become 8
BIt would stay 4.5
CIt would become 6
DIt would become 9
💡 Hint
Recall inner integral at x=1 is integral of y dy from 0 to upper limit; use formula y^2/2
Concept Snapshot
dblquad syntax: dblquad(f, x_lower, x_upper, y_lower(x), y_upper(x))
Function f(y,x) integrates first over y, then x.
Limits for y can depend on x.
Returns integral value and error estimate.
Used for calculating area/volume under surfaces.
Full Transcript
This visual execution traces how the scipy dblquad function calculates a double integral. We start by defining the function f(y,x) and the integration limits for x and y. The integration proceeds by first computing the inner integral over y for fixed x values, then summing these results over x. The execution table shows step-by-step inner integral values at sample x points and the accumulation to the final integral result. Key points include the argument order of f(y,x), the use of limits for y as functions of x, and the two-stage integration process. The visual quiz tests understanding of these steps and how changing limits affects results.