Tutorials › Calculus I › The Square Function and Sums of Squares

Riemann Sums and the Integral · Tutorial 956 of 1495

The Square Function and Sums of Squares

Use uniform partitions and the formula for the first \(n\) squares to evaluate the integral of \(x^2\) directly from its Riemann sums.

Intermediate 9 min read

What You'll Learn

  • Write the uniform right-endpoint Riemann sum for \(x^2\) on an interval.
  • Prove the formula for the sum of the first \(n\) squares.
  • Evaluate the resulting Riemann-sum limit on intervals starting at zero.
  • Extend the calculation to an arbitrary interval \([a,b]\).
  • Identify why the interval width must multiply each sampled function value.
  • Check an integral value against the formula obtained from the Riemann sums.

Why Squares Lead to an Exact Integral

A definite integral can be defined through limits of Riemann sums. For the square function, \(f(x)=x^2\), uniform partitions make those sums especially manageable: the sample points are equally spaced, and their squared values involve the familiar sum \(1^2+2^2+\cdots+n^2\).

The calculation has two important parts. First, we need an exact formula for that sum of squares. Then we use the formula inside a Riemann sum and let the number of subintervals grow. This gives an exact value for the integral without using antiderivatives.

Definition: For an interval \([a,b]\) with \(a<b\), a uniform partition into \(n\) subintervals has width \(\Delta x=(b-a)/n\). Its right endpoints are \(x_k=a+k\Delta x\), for \(k=1,\ldots,n\). The right-endpoint Riemann sum for \(f\) is \(\sum_{k=1}^{n} f(x_k)\Delta x\).

The factor \(\Delta x\) represents the width of each subinterval. A Riemann sum adds the sampled function value multiplied by that width; the sum of sampled values by itself is not the Riemann sum.

The Formula for the First \(n\) Squares

The key finite-sum identity is

$$ \sum_{k=1}^{n} k^2 = 1^2+2^2+\cdots+n^2 = \frac{n(n+1)(2n+1)}{6}. $$

Here \(n\) is a positive integer. We prove the identity by induction, so the formula is justified for every positive integer rather than inferred from a few examples.

1
Base case.
For \(n=1\), the left side is \(1^2=1\), and the right side is \(1(2)(3)/6=1\). The identity holds at \(n=1\).
2
Inductive assumption.
Assume for some positive integer \(n\) that \(\sum_{k=1}^{n}k^2=n(n+1)(2n+1)/6\).
3
Add the next square.
Then \(\sum_{k=1}^{n+1}k^2=\sum_{k=1}^{n}k^2+(n+1)^2\). Substitute the assumed formula and simplify to obtain the formula with \(n+1\).

For completeness, the simplification in the last step is

$$ \begin{aligned} \sum_{k=1}^{n+1}k^2 &=\frac{n(n+1)(2n+1)}{6}+(n+1)^2\\ &=\frac{(n+1)\bigl(n(2n+1)+6(n+1)\bigr)}{6}\\ &=\frac{(n+1)(2n^2+7n+6)}{6}\\ &=\frac{(n+1)(n+2)(2n+3)}{6}. \end{aligned} $$

The final expression is exactly \((n+1)((n+1)+1)(2(n+1)+1)/6\). Thus the identity holds at \(n+1\), completing the induction.

We will also use \(\sum_{k=1}^{n}k=n(n+1)/2\). This follows by pairing the first and last terms: each pair has sum \(n+1\), and the resulting formula applies whether \(n\) is even or odd.

First Calculation: The Integral on \([0,1]\)

Worked Example: Integrating \(x^2\) from 0 to 1

Divide \([0,1]\) into \(n\) equal subintervals. The width is \(\Delta x=1/n\), and the \(k\)-th right endpoint is \(x_k=k/n\). The right-endpoint sum is

$$ \begin{aligned} S_n &=\sum_{k=1}^{n}\left(\frac{k}{n}\right)^2\frac{1}{n}\\ &=\frac{1}{n^3}\sum_{k=1}^{n}k^2\\ &=\frac{1}{n^3}\cdot\frac{n(n+1)(2n+1)}{6}\\ &=\frac{(n+1)(2n+1)}{6n^2}\\ &=\frac{2n^2+3n+1}{6n^2}\\ &=\frac{1}{3}+\frac{1}{2n}+\frac{1}{6n^2}. \end{aligned} $$

As \(n\) tends to infinity, \(1/(2n)\) and \(1/(6n^2)\) both tend to zero. Therefore \(S_n\) tends to \(1/3\). Since \(x^2\) is continuous on the closed interval \([0,1]\), it is Riemann integrable there, and its integral equals this limit:

$$ \int_0^1 x^2\,dx=\frac{1}{3}. $$

Check: the endpoint formula derived below gives \((1^3-0^3)/3=1/3\), the same value as the Riemann-sum limit.

A Second Interval

Worked Example: Integrating \(x^2\) from 0 to 2

Now the width is \(\Delta x=2/n\), and the right endpoints are \(x_k=2k/n\). Each term is the function value at that endpoint multiplied by the width:

$$ \begin{aligned} S_n &=\sum_{k=1}^{n}\left(\frac{2k}{n}\right)^2\frac{2}{n}\\ &=\sum_{k=1}^{n}\frac{4k^2}{n^2}\cdot\frac{2}{n}\\ &=\frac{8}{n^3}\sum_{k=1}^{n}k^2\\ &=\frac{8}{n^3}\cdot\frac{n(n+1)(2n+1)}{6}\\ &=\frac{4(n+1)(2n+1)}{3n^2}\\ &=\frac{4(2n^2+3n+1)}{3n^2}\\ &=\frac{8}{3}+\frac{4}{n}+\frac{4}{3n^2}. \end{aligned} $$

The last two terms tend to zero, so \(\lim_{n\to\infty}S_n=8/3\). Thus

$$ \int_0^2x^2\,dx=\frac{8}{3}. $$

Check: the general endpoint expression gives \((2^3-0^3)/3=8/3\), confirming the result.

General Interval: The Riemann-Sum Derivation

Let \(a<b\) be real numbers. Divide \([a,b]\) into \(n\) equal pieces, so that \(\Delta x=(b-a)/n\). To keep the algebra readable, set \(L=b-a\). The right endpoints are \(x_k=a+kL/n\), and the right-endpoint sum is

$$ S_n=\frac{L}{n}\sum_{k=1}^{n}\left(a+\frac{kL}{n}\right)^2. $$

Expand the square and separate the sums. The constant term occurs \(n\) times, the terms proportional to \(k\) use the sum of the first \(n\) integers, and the terms proportional to \(k^2\) use the sum-of-squares formula:

$$ \begin{aligned} S_n &=\frac{L}{n}\sum_{k=1}^{n} \left(a^2+\frac{2akL}{n}+\frac{k^2L^2}{n^2}\right)\\ &=\frac{L}{n}\left( na^2+\frac{2aL}{n}\sum_{k=1}^{n}k +\frac{L^2}{n^2}\sum_{k=1}^{n}k^2 \right)\\ &=\frac{L}{n}\left( na^2+\frac{2aL}{n}\cdot\frac{n(n+1)}{2} +\frac{L^2}{n^2}\cdot\frac{n(n+1)(2n+1)}{6} \right)\\ &=a^2L+\frac{aL^2(n+1)}{n} +\frac{L^3(n+1)(2n+1)}{6n^2}\\ &=a^2L+aL^2\left(1+\frac{1}{n}\right) +\frac{L^3}{6}\left(2+\frac{3}{n}+\frac{1}{n^2}\right). \end{aligned} $$

As \(n\to\infty\), the terms containing \(1/n\) or \(1/n^2\) vanish. Consequently,

$$ \lim_{n\to\infty}S_n =a^2L+aL^2+\frac{L^3}{3}. $$

Since \(L=b-a\), this limit can be written in terms of the endpoints. Indeed,

$$ \begin{aligned} a^2L+aL^2+\frac{L^3}{3} &=\frac{3a^2L+3aL^2+L^3}{3}\\ &=\frac{(a+L)^3-a^3}{3}\\ &=\frac{b^3-a^3}{3}. \end{aligned} $$

The middle equality follows by expanding \((a+L)^3=a^3+3a^2L+3aL^2+L^3\). This computation explains why the endpoint expression emerges: the finite Riemann sum has terms that approach the expansion of the difference of two cubes.

Theorem: For real numbers \(a<b\), the square function \(f(x)=x^2\) is continuous, hence Riemann integrable, on \([a,b]\). Its uniform right-endpoint sums converge to $$ \int_a^b x^2\,dx=\frac{b^3-a^3}{3}. $$ The formula is established here for intervals with \(a<b\); the argument uses uniform partitions of such an interval and the right endpoints specified above.

Using the General Calculation

Worked Example: Integrating \(x^2\) from 1 to 3

Take \(a=1\), \(b=3\), and \(L=2\). The right endpoints are \(x_k=1+2k/n\), while each subinterval has width \(2/n\). Expanding the sum gives

$$ \begin{aligned} S_n &=\frac{2}{n}\sum_{k=1}^{n}\left(1+\frac{2k}{n}\right)^2\\ &=\frac{2}{n}\sum_{k=1}^{n} \left(1+\frac{4k}{n}+\frac{4k^2}{n^2}\right)\\ &=\frac{2}{n}\left( n+\frac{4}{n}\cdot\frac{n(n+1)}{2} +\frac{4}{n^2}\cdot\frac{n(n+1)(2n+1)}{6} \right)\\ &=2+\frac{4(n+1)}{n} +\frac{4(n+1)(2n+1)}{3n^2}\\ &=2+4\left(1+\frac{1}{n}\right) +\frac{4}{3}\left(2+\frac{3}{n}+\frac{1}{n^2}\right)\\ &=\frac{26}{3}+\frac{8}{n}+\frac{4}{3n^2}. \end{aligned} $$

The terms involving \(1/n\) and \(1/n^2\) tend to zero, so the sum tends to \(26/3\). Therefore \(\int_1^3x^2\,dx=26/3\). Check using the endpoint formula: \((3^3-1^3)/3=(27-1)/3=26/3\).

Common Mistake: Leaving Out the Width

A frequent error is to compute the function values at the sample points and add them without multiplying by \(\Delta x\). On \([0,1]\), the right endpoints are \(k/n\). The incorrect calculation would be

$$ \text{Wrong:}\qquad \sum_{k=1}^{n}\left(\frac{k}{n}\right)^2 =\frac{1}{n^2}\cdot\frac{n(n+1)(2n+1)}{6}. $$

This expression is approximately \(n/3\), so it grows rather than approaching the integral. The mistake is that it adds heights, not rectangle areas. Each height must be multiplied by the subinterval width \(1/n\):

$$ \text{Correct:}\qquad \sum_{k=1}^{n}\left(\frac{k}{n}\right)^2\frac{1}{n} =\frac{(n+1)(2n+1)}{6n^2} \longrightarrow \frac{1}{3}. $$

Another error is to use the sum-of-squares formula with an incorrect power of \(n\). For \([0,1]\), the sampled square contributes \(k^2/n^2\), and the width contributes a further factor \(1/n\). Together these give \(k^2/n^3\), not \(k^2/n^2\). Keeping the sample value and the width visible in the first line helps prevent this error.

When the Result Applies

The derivation requires a finite interval with \(a<b\), uniform subintervals, and right endpoints \(a+k(b-a)/n\). The function is specifically \(x^2\), which is continuous on every closed bounded interval \([a,b]\). By the earlier result that continuous functions are Riemann integrable, the limit of these tagged sums equals the definite integral. The finite-sum formulas apply for every positive integer \(n\), and the integral value follows by taking \(n\to\infty\).

The procedure is useful because it turns the definition of the integral into a concrete calculation: identify the width and sample points, expand the sampled function, apply finite-sum identities, and take the limit. The sum-of-squares identity is not merely a shortcut; it is the exact algebraic step that makes this Riemann-sum evaluation possible.

Check Your Understanding

For each question, keep the subinterval width visible and use the sum-of-squares formula where needed.

  1. For the uniform right-endpoint partition of \([0,1]\), what are \(\Delta x\) and \(x_k\)?
  2. State the formula for \(\sum_{k=1}^{n}k^2\), and identify the positive-integer condition on \(n\).
  3. Write the right-endpoint sum for \(x^2\) on \([0,2]\) before simplifying it.
  4. Why does the sum \(\sum_{k=1}^{n}(k/n)^2\) alone fail to be the Riemann sum on \([0,1]\)?
  5. Use the endpoint formula to evaluate the integral of \(x^2\) on \([1,2]\).
  6. Name the continuity and integrability condition that lets the limiting tagged sums equal the definite integral on \([a,b]\).

Test yourself: Calculus I final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon