Math Applets

RienmanSum

Riemann integral:

Let f:[a,b]Rf : [a,b] \to \mathbb{R} be bounded.

i) The value

abf(x)dx:=inf{I(φ)fφ,  φ is a staircase function}\overline{\int_a^b} f(x)\,dx := \inf \{\, I(\varphi) \mid f \le \varphi,\; \varphi \text{ is a staircase function} \,\}

is called the upper integral of ff.

ii) The value

abf(x)dx:=sup{I(φ)φf,  φ is a staircase function}\underline{\int_a^b} f(x)\,dx := \sup \{\, I(\varphi) \mid \varphi \le f,\; \varphi \text{ is a staircase function} \,\}

is called the lower integral of ff.

iii) The function ff is (Riemann) integrable if

abf(x)dx=abf(x)dx.\overline{\int_a^b} f(x)\,dx = \underline{\int_a^b} f(x)\,dx.

In this case, we define

abf(x)dx:=abf(x)dx=abf(x)dx,\int_a^b f(x)\,dx := \overline{\int_a^b} f(x)\,dx = \underline{\int_a^b} f(x)\,dx,

and call it the (Riemann) integral of ff.


How to use the applet

  • Drag the two blue points on the xx-axis to choose the interval [a,b][a,b].
  • Move the slider nn to choose the number of subintervals in the partition a=x0<x1<<xn=b.a=x_0<x_1<\dots<x_n=b.
  • Click “Randomize partition” to generate a new random partition with the same number nn.
  • Move the slider δ\delta to control how “loose” the upper and lower staircase bounds are.
  • The blue curve is the function ff.
  • The red rectangles form an upper staircase function: on each subinterval [xi1,xi][x_{i-1},x_i] the height is Mi+δM_i+\delta, where Mi=supx[xi1,xi]f(x).M_i=\sup_{x\in[x_{i-1},x_i]} f(x).
  • The green rectangles form a lower staircase function: on each subinterval the height is miδm_i-\delta, where mi=infx[xi1,xi]f(x).m_i=\inf_{x\in[x_{i-1},x_i]} f(x).
  • The green step function stays below ff, and the red step function stays above ff (by construction).
  • Decreasing δ\delta toward 00 makes the bounds tighter for the chosen partition.
  • Increasing nn (more, finer subintervals) typically makes the upper and lower step functions closer, illustrating why integrable functions have matching upper and lower integrals in the limit of finer partitions.

Loading graph…
  • Hold Shift + scroll to zoom
  • Hold Shift + drag to move
  • Points shaped like <> act as sliders

Description

Link to code.

Reference: Lecture Notes Calculus 1 ( May22,2022 ) Definition7.5 page 125

This applet illustrates the idea behind the lower and upper integrals definition. The function is fixed in the code as const f = (x: number) => 0.25 * x ** 3 - x ** 2 - x + 2;. The interval [a,b][a,b] is controlled by two draggable points.

The slider nSlider sets the number of subintervals in a partition Z:a=x0<<xn=bZ: a=x_0<\dots<x_n=b. The partition is randomized by assigning random positive “weights” randomWeights = Array.from({ length: MAX_PARTITIONS }, () => Math.random() * 0.8 + 0.3); and converting them into cut points with the helper buildRandomCuts(n, start, end). Pressing the button “Randomize partition” regenerates these weights and therefore produces a new random partition.

On each subinterval [xi1,xi][x_{i-1},x_i] the applet computes mi=infx[xi1,xi]f(x)m_i=\inf_{x\in[x_{i-1},x_i]} f(x) and Mi=supx[xi1,xi]f(x)M_i=\sup_{x\in[x_{i-1},x_i]} f(x). Since ff is a cubic polynomial, these extrema are attained at the endpoints and at critical points (zeros of ff'). In the code the two critical points are precomputed in criticalPoints, and the values mim_i and MiM_i are computed by the function:

const extremaOnInterval = (x1: number, x2: number) => {
    let minVal = Math.min(f(x1), f(x2));
    let maxVal = Math.max(f(x1), f(x2));

    for (const c of criticalPoints) {
    if (c >= x1 - EPS && c <= x2 + EPS) {
        const v = f(c);
        minVal = Math.min(minVal, v);
        maxVal = Math.max(maxVal, v);
    }
    }
    return { min: minVal, max: maxVal };
};

The red rectangles represent an upper staircase function and the green rectangles represent a lower staircase function. Their shapes are produced by the two JSXGraph curves upperCurve and lowerCurve. For each subinterval, the rectangle heights are built in computeRectangleCurve(cuts, type).

The slider deltaSlider controls how tight these staircase bounds are. On each subinterval the applet draws the lower bound with height miδm_i-\delta and the upper bound with height Mi+δM_i+\delta: const h = type === "upper" ? max + delta : min - delta; This guarantees that the green staircase function stays below ff and the red staircase function stays above ff. When δ\delta is decreased toward 00, the bounds become tighter and approach the “best” lower and upper step functions associated to the chosen partition.

const computeRectangleCurve = (cuts: number[], type: "upper" | "lower") => {
    const X: number[] = [];
    const Y: number[] = [];
    const delta = Math.max(0, deltaSlider.Value());

    for (let i = 0; i < cuts.length - 1; i++) {
    const x1 = cuts[i];
    const x2 = cuts[i + 1];
    const { min, max } = extremaOnInterval(x1, x2);

    const h = type === "upper" ? max + delta : min - delta;

    X.push(x1, x1, x2, x2);
    Y.push(0, h, h, 0);
    }

    return { X, Y };
};