5.4.9 · D1Scientific Computing (Python)

Foundations — scipy.integrate — odeint, solve_ivp (RK45, DOP853), quad

1,929 words9 min readBack to topic

Before you can read the parent note you must own every symbol it uses without stumbling. Below, each symbol is built from nothing: plain words → the picture → why the topic needs it. Read top to bottom; each rung stands on the one below.


1. The function — a machine that turns a number into a number

Picture a curve drawn on paper. The horizontal axis is the input ; the height of the curve above that point is the output .

Figure — scipy.integrate — odeint, solve_ivp (RK45, DOP853), quad

Why the topic needs it: everything in this module is about a function. quad wants the area under ; the ODE solvers are handed a function that reports a slope. If "function" is fuzzy, nothing downstream makes sense.


2. The interval and the symbols

On the picture from figure 1, and are two vertical fence-posts on the horizontal axis. The strip of area we care about lives between them.

Why the topic needs it: quad(f, a, b) asks for the area of only between these two posts. For ODEs the analogous pair is — the start and end time.


3. — a small width, and the idea of "tiny piece"

Figure — scipy.integrate — odeint, solve_ivp (RK45, DOP853), quad

Look at the amber rectangle in figure 2: its width is and its height is at some sample point . Its area is .

Why the topic needs it: the whole trick of numerical integration is chopping a smooth thing into many pieces each of width , and later letting that width shrink toward zero.


4. The sum symbol — "add up all these pieces"

So literally reads: take rectangle 1's area, plus rectangle 2's area, plus …. That is a Riemann sum — figure 2 shows all the amber rectangles being counted.

Why the topic needs it: quad is literally a weighted sum — see the next symbol.


5. The integral sign

WHAT this line says: the integral is the limit of the rectangle-sum as the slivers get infinitely thin. WHY the limit: thinner rectangles hug the curve better, so the error vanishes. WHAT IT LOOKS LIKE: figure 2's jagged rectangle-tops smoothing into the true curve as they multiply.

Why the topic needs it: this exact symbol is what quad(f, a, b) computes. No integral sign → no quad.


6. The weights and sample points

In a plain Riemann sum every weight is the same (). Smart rules (Gaussian quadrature) pick unequal weights and clever sample spots so that few points give big accuracy. The parent's Simpson's rule has weights — the middle sample counts four times as much.

Why the topic needs it: quad uses adaptive Gauss–Kronrod weights; understanding "weighted sum" is what makes that phrase meaningful.


7. The derivative — a slope, a speed

Figure — scipy.integrate — odeint, solve_ivp (RK45, DOP853), quad

The red line in figure 3 is tangent to the curve — it just grazes it. Its steepness IS at that point. Steep line = changing fast; flat line = barely changing.

Why the topic needs it: an ODE hands you the slope and asks for the path. Also written (a dot on top = "derivative in time").


8. The dot notation and

Picture a swing: is how far it is displaced, is how fast it's moving, is how hard it's being tugged back. That is the Harmonic oscillator the parent solves, .

Why the topic needs it: second-order ODEs use ; you must rewrite them as two first-order equations because solvers only eat first-order (, one dot) systems.


9. The step size and index

Figure — scipy.integrate — odeint, solve_ivp (RK45, DOP853), quad

Figure 4: starting dot , follow the tangent slope for a width , land at . The gap between that landing point and the true curve is the step error — smaller , smaller gap.

Why the topic needs it: the update rule (Euler) and the fancier Runge-Kutta methods are all written in these symbols.


10. The starting value and

Same speed-recipe but different starting spots give different journeys — like two cars obeying the same speed law but starting on different streets. The pair chooses one.

Why the topic needs it: this is the "Initial" in Initial Value Problem; solve_ivp(f, [t0,tf], y0) demands it.


11. and — the last two Greek guests

Why the topic needs it: appears in the oscillator ; appears in Simpson's error — it just says "evaluated at some hidden point".


The prerequisite map

function f(x)

area under curve

interval a to b

small width delta x

Riemann sum

summation sigma

quad numerical integral

weights and sample points

derivative dy dt

forward step rule

step size h and index n

initial value y0

solve_ivp and odeint

dot notation for acceleration

scipy.integrate

The left branch (function + interval + slivers + sum) feeds quad. The right branch (slope + step + start point) feeds solve_ivp/odeint. Both meet at the module. The connective tissue is the Fundamental Theorem of Calculus: it says accumulating slope is the same act as computing area — which is exactly why one module holds both.


Equipment checklist

Cover the right side; can you answer before revealing?

What does mean in one sentence?
A rule that takes one number and returns one number, drawn as a curve of height .
What do the brackets in tell you?
All numbers from to , endpoints included — the fence-posts bounding the region.
What is ?
A small step/width in — the width of one thin sliver.
Read in words.
Add up the area of every thin rectangle: height times width .
What does compute, and what is ?
The exact area under between and ; is the infinitely thin width that becomes in the limit.
What are and ?
is where you sample the function; is how much that sample counts in the weighted total.
What does measure, geometrically?
The slope of the tangent line — the rate at which changes as advances (a "speed").
Difference between and ?
One dot is the first time-derivative (velocity); two dots is the second (acceleration).
What are and the subscript in ?
is the size of one forward time-step; counts steps, so is the value after steps.
What does the initial condition pin down?
Which single trajectory we walk, out of all paths obeying the same slope rule.
What do and stand for?
is angular frequency (speed of oscillation); is an unknown point inside the interval used in error formulas.