<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Numerical integration | Nicholas Hu</title>
    <link>https://www.math.ucla.edu/~njhu/notes/na/numint/</link>
      <atom:link href="https://www.math.ucla.edu/~njhu/notes/na/numint/index.xml" rel="self" type="application/rss+xml" />
    <description>Numerical integration</description>
    <generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en-ca</language><lastBuildDate>Wed, 04 Mar 2026 00:00:00 +0000</lastBuildDate>
    <image>
      <url>https://www.math.ucla.edu/~njhu/media/icon_hu_d46824b1c45312fd.png</url>
      <title>Numerical integration</title>
      <link>https://www.math.ucla.edu/~njhu/notes/na/numint/</link>
    </image>
    
    <item>
      <title>Newton–Cotes quadrature</title>
      <link>https://www.math.ucla.edu/~njhu/notes/na/numint/newtoncotes/</link>
      <pubDate>Wed, 04 Mar 2026 00:00:00 +0000</pubDate>
      <guid>https://www.math.ucla.edu/~njhu/notes/na/numint/newtoncotes/</guid>
      <description>&lt;div class=&#34;btn-links mb-3&#34;&gt;
&lt;a class=&#34;btn btn-outline-primary btn-page-header btn-sm&#34; href=&#34;../newtoncotes.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;
  PDF
&lt;/a&gt;
&lt;/div&gt;
&lt;!--
No newlines allowed between $$&#39;s below!
--&gt;
&lt;div style=&#34;display: none;&#34;&gt;
$$
%% Sets and functions %%
\newcommand{\set}[1]{\{ #1 \}}
\newcommand{\Set}[1]{\left \{ #1 \right\}}
\renewcommand{\emptyset}{\varnothing}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Rn}{\mathbb{R}^n}
\newcommand{\Rm}{\mathbb{R}^m}
\newcommand{\C}{\mathbb{C}}
%% Linear algebra %%
\newcommand{\abs}[1]{\lvert #1 \rvert}
\newcommand{\Abs}[1]{\left\lvert #1 \right\rvert}
\newcommand{\inner}[2]{\langle #1, #2 \rangle}
\newcommand{\Inner}[2]{\left\langle #1, #2 \right\rangle}
\newcommand{\norm}[1]{\lVert #1 \rVert}
\newcommand{\Norm}[1]{\left\lVert #1 \right\rVert}
\newcommand{\trans}{{\top}}
\newcommand{\span}{\mathop{\mathrm{span}}}
$$
&lt;/div&gt;
&lt;!-- BODY --&gt;
&lt;p&gt;Consider the approximation of 

$I(f) := \int_a^b f(x) \, dx$ for integrable 

$f : [a, b] \to \R$ by a &lt;strong&gt;quadrature formula&lt;/strong&gt; of the form 

$I_n(f) := \sum_{j=0}^n w_j f(x_j)$, where 

$\set{w_j}_{j=0}^n \subseteq \R$ are &lt;strong&gt;weights&lt;/strong&gt; and 

$\set{x_j}_{j=0}^n \subseteq [a, b]$ are &lt;em&gt;distinct&lt;/em&gt; &lt;strong&gt;nodes&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;precision&lt;/strong&gt; of a quadrature formula is the greatest 

$m$ for which 

$I_n = I$ on 

$P_m$ (the vector space of real polynomial functions of degree &lt;em&gt;at most&lt;/em&gt; 

$m$). For such an 

$m$ to exist, we assume that 

$\sum_{j=0}^n w_j = I_n(1) = I(1) = b-a$ so that 

$I_n = I$ on 

$P_0$ by linearity, while also noting that 

$m \leq 2n+1$ since 

$I_n(\omega_{n+1}^2) = 0 &lt; I(\omega_{n+1}^2)$ for 

$\omega_{n+1} := \prod_{j=0}^n (\bullet - x_j) \in P_{n+1}$. In addition, Lagrange interpolation shows that 

$m \geq n$ if and only if 

$I_n(f) = I(p_n)$ for all 

$f$, where 

$p_n \in P_n$ interpolates 

$f$ at the nodes; or equivalently, 

$w_j = I(\ell_j)$ for all 

$j$, where 

$\set{\ell_j}_{j=0}^n$ is the Lagrange basis of 

$P_n$. Such a formula is called &lt;strong&gt;interpolatory&lt;/strong&gt; and its error can be expressed as


$$
I(f) - I_n(f) = I(f-p_n) = \int_a^b f[x_0, \dots, x_n, x] \omega_{n+1}(x) \, dx.
$$&lt;/p&gt;
&lt;h2 id=&#34;closed-newtoncotes-formulas&#34;&gt;Closed Newton–Cotes formulas&lt;/h2&gt;
&lt;p&gt;For 

$n \geq 1$, the 

$(n+1)$-point &lt;strong&gt;closed Newton–Cotes formula&lt;/strong&gt; is the interpolatory quadrature formula with 

$x_j := a + jh$, where 

$h := \frac{b-a}{n}$.&lt;/p&gt;
&lt;p&gt;To analyze its error, we define the polynomials 

$\Omega_j(x) := \int_a^x \omega_j(t) \, dt$ for 

$1 \leq j \leq n+1$. We claim that 

$\Omega_j \geq 0$ or 

$\Omega_j \leq 0$ on 

$[a, x_{j-1}]$ according as 

$j$ is odd or even. This claim is trivial for 

$j = 1$, and if it holds for some 

$j$, integration by parts gives 

$\Omega_{j+1}(x) = \Omega_j(x)(x-x_j) - \int_a^x \Omega_j(t) \, dt$, which implies that the desired inequality for 

$\Omega_{j+1}$ holds on 

$[a, x_{j-1}]$. Furthermore, 

$\Omega_{j+1}$ is decreasing on 

$[x_{j-1}, x_j]$, so if 

$j$ is odd, then 

$\Omega_{j+1}(x) \leq \Omega_{j+1}(x_{j-1}) \leq 0$ for all 

$x \in [x_{j-1}, x_j]$, whereas if 

$j$ is even, then 

$\Omega_{j+1}(x) \geq \Omega_{j+1}(x_j) = 0$ for all 

$x \in [x_{j-1}, x_j]$ by the symmetry of 

$\omega_{j+1}$, which establishes the claim by induction.&lt;/p&gt;
&lt;p&gt;In fact, if 

$j$ is odd, then 

$\Omega_j \geq 0$ everywhere because 

$\Omega_j$ is decreasing on 

$(-\infty, a]$ and increasing on 

$[x_{j-1}, \infty)$. We also note that 

$\int_a^b \Omega_j(x) \, dx = -\int_a^b (t-b) \omega_j(t) \, dt$ for all 

$j$.&lt;/p&gt;
&lt;p&gt;Now if 

$n$ is even and 

$f \in C^{n+2}([a, b])$, integration by parts and the mean value theorems for integrals and divided differences yield


$$
\begin{align*}
\int_a^b f[x_0, \dots, x_n, x] \omega_{n+1}(x) \, dx
&amp;= -\int_a^b f[x_0, \dots, x_n, x, x] \Omega_{n+1}(x) \, dx \\
&amp;= - \frac{f^{(n+2)}(\xi)}{(n+2)!} \int_a^b \Omega_{n+1}(x) \, dx 
\quad \text{for some 

$\xi \in (a, b)$} \\
&amp;= \frac{f^{(n+2)}(\xi)}{(n+2)!} \int_a^b t \omega_{n+1}(t) \, dt.
\end{align*}
$$
If 

$n$ is odd and 

$f \in C^{n+1}([a, b])$, we have


$$
\begin{align*}
\int_a^b f[x_0, \dots, x_n, x] \omega_{n+1}(x) \, dx
&amp;= \int_a^b \bigl( f[x_0, \dots, x_{n-1}, x] - f[x_0, \dots, x_n] \bigr) \omega_n(x) \, dx \\
&amp;= -\int_a^b f[x_0, \dots, x_{n-1}, x, x] \Omega_n(x) \, dx \\
&amp;= -\frac{f^{(n+1)}(\xi)}{(n+1)!} \int_a^b \Omega_n(x) \, dx
\quad \text{for some 

$\xi \in (a, b)$} \\
&amp;= \frac{f^{(n+1)}(\xi)}{(n+1)!} \int_a^b \omega_{n+1}(t) \, dt.
\end{align*}
$$
In summary, we obtain the following (where we have changed variables affinely to exhibit the dependence of the error and the weights on 

$h$).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Error of closed Newton–Cotes formulas&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If 

$n$ is even and 

$f \in C^{n+2}([a, b])$, then there exists a 

$\xi \in (a, b)$ such that


$$
I(f) - I_n(f) = C_n f^{(n+2)}(\xi) h^{n+3},
\quad
C_n := \frac{1}{(n+2)!} \int_0^n x^2 (x-1) \cdots (x-n) \, dx.
$$
If 

$n$ is odd and 

$f \in C^{n+1}([a, b])$, then there exists a 

$\xi \in (a, b)$ such that


$$
I(f) - I_n(f) = C_n f^{(n+1)}(\xi) h^{n+2},
\quad
C_n := \frac{1}{(n+1)!} \int_0^n x(x-1) \cdots (x-n) \, dx.
$$&lt;/p&gt;
&lt;/blockquote&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;

$n$&lt;/th&gt;
          &lt;th&gt;

$w_j / h$&lt;/th&gt;
          &lt;th&gt;

$C_n$&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;

$1$ (&lt;strong&gt;trapezoidal rule&lt;/strong&gt;)&lt;/td&gt;
          &lt;td&gt;

$\frac{1}{2}, \frac{1}{2}$&lt;/td&gt;
          &lt;td&gt;

$-\frac{1}{12}$&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;

$2$ (&lt;strong&gt;Simpson’s rule&lt;/strong&gt;)&lt;/td&gt;
          &lt;td&gt;

$\frac{1}{3}, \frac{4}{3}, \frac{1}{3}$&lt;/td&gt;
          &lt;td&gt;

$-\frac{1}{90}$&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;

$3$ (&lt;strong&gt;Simpson’s 3/8 rule&lt;/strong&gt;)&lt;/td&gt;
          &lt;td&gt;

$\frac{3}{8}, \frac{9}{8}, \frac{9}{8}, \frac{3}{8}$&lt;/td&gt;
          &lt;td&gt;

$-\frac{3}{80}$&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;

$4$ (&lt;strong&gt;Boole’s rule&lt;/strong&gt;)&lt;/td&gt;
          &lt;td&gt;

$\frac{14}{45}, \frac{64}{45}, \frac{8}{15}, \frac{64}{45}, \frac{14}{45}$&lt;/td&gt;
          &lt;td&gt;

$-\frac{8}{945}$&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;open-newtoncotes-formulas&#34;&gt;Open Newton–Cotes formulas&lt;/h2&gt;
&lt;p&gt;For 

$n \geq 0$, the 

$(n+1)$-point &lt;strong&gt;open Newton–Cotes formula&lt;/strong&gt; is the interpolatory quadrature formula with 

$x_j := a + (j+1)h$, where 

$h := \frac{b-a}{n+2}$.&lt;/p&gt;
&lt;p&gt;As above, we define 

$\Omega_j(x) := \int_a^x \omega_j(t) \, dt$ for 

$0 \leq j \leq n+1$; an analogous argument shows that 

$\Omega_j \geq 0$ or 

$\Omega_j \leq 0$ on 

$[a, x_j]$ according as 

$j$ is even or odd, where 

$x_{n+1} := b$. Thus, if 

$n$ is even and 

$f \in C^{n+2}([a, b])$, the same argument as before yields


$$
\begin{align*}
\int_a^b f[x_0, \dots, x_n, x] \omega_{n+1}(x) \, dx
&amp;= \frac{f^{(n+2)}(\xi)}{(n+2)!} \int_a^b t \omega_{n+1}(t) \, dt \quad \text{for some 

$\xi \in (a, b)$}.
\end{align*}
$$
However, if 

$n$ is odd and 

$f \in C^{n+1}([a, b])$, then 

$\Omega_n$ changes sign at 

$x_n = b - h$, so the mean value theorem for integrals is not applicable on 

$[a, b]$ as before. Instead, we write


$$
\begin{align*}
\int_a^b f[x_0, \dots, x_n, x] \omega_{n+1}(x) \, dx
&amp;= \int_a^{x_n} f[x_0, \dots, x_n, x] \omega_{n+1}(x) \, dx 
+ \int_{x_n}^b f[x_0, \dots, x_n, x] \omega_{n+1}(x) \, dx \\
&amp;= \frac{f^{(n+1)}(\xi_1)}{(n+1)!} \int_a^{x_n} \omega_{n+1}(x) \, dx + \frac{f^{(n+1)}(\xi_2)}{(n+1)!} \int_{x_n}^b \omega_{n+1}(x) \, dx
\\
&amp;\hphantom{{}={}} \text{for some 

$\xi_1, \xi_2 \in (a, b)$}.
\end{align*}
$$
Since 

$\int_a^{x_n} \omega_{n+1}(x) \, dx = \Omega_{n+1}(x_n) \geq 0$ and 

$\int_{x_n}^b \omega_{n+1}(x) \, dx \geq 0$, the intermediate value theorem implies that this sum is equal to


$$
\frac{f^{(n+1)}(\xi)}{(n+1)!} \left( \int_a^{x_n} \omega_{n+1}(x) \, dx + \int_{x_n}^b \omega_{n+1}(x) \, dx \right)
=
\frac{f^{(n+1)}(\xi)}{(n+1)!} \int_a^b \omega_{n+1}(x) \, dx
\quad \text{for some 

$\xi \in (a, b)$}.
$$&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Error of open Newton–Cotes formulas&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If 

$n$ is even and 

$f \in C^{n+2}([a, b])$, then there exists a 

$\xi \in (a, b)$ such that


$$
I(f) - I_n(f) = C_n f^{(n+2)}(\xi) h^{n+3},
\quad
C_n := \frac{1}{(n+2)!} \int_{-1}^{n+1} x^2 (x-1) \cdots (x-n) \, dx.
$$
If 

$n$ is odd and 

$f \in C^{n+1}([a, b])$, then there exists a 

$\xi \in (a, b)$ such that


$$
I(f) - I_n(f) = C_n f^{(n+1)}(\xi) h^{n+2},
\quad
C_n := \frac{1}{(n+1)!} \int_{-1}^{n+1} x(x-1) \cdots (x-n) \, dx.
$$&lt;/p&gt;
&lt;/blockquote&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;

$n$&lt;/th&gt;
          &lt;th&gt;

$w_j / h$&lt;/th&gt;
          &lt;th&gt;

$C_n$&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;

$0$ (&lt;strong&gt;midpoint rule&lt;/strong&gt;)&lt;/td&gt;
          &lt;td&gt;

$2$&lt;/td&gt;
          &lt;td&gt;

$\frac{1}{3}$&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;

$1$&lt;/td&gt;
          &lt;td&gt;

$\frac{3}{2}, \frac{3}{2}$&lt;/td&gt;
          &lt;td&gt;

$\frac{3}{4}$&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;

$2$&lt;/td&gt;
          &lt;td&gt;

$\frac{8}{3}, -\frac{4}{3}, \frac{8}{3}$&lt;/td&gt;
          &lt;td&gt;

$\frac{14}{45}$&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;

$3$&lt;/td&gt;
          &lt;td&gt;

$\frac{55}{24}, \frac{5}{24}, \frac{5}{24}, \frac{55}{24}$&lt;/td&gt;
          &lt;td&gt;

$\frac{95}{144}$&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
</description>
    </item>
    
  </channel>
</rss>
