# Sample Programs

Sample programs for Minimal BASIC will appear here.

## Numerical Integration

### Introduction

There exists two cases, when the computation of the value of a definite integral by numerical methods is needed. One of them is the calculation of the area below the curve defined by a set of experimental data, and another is the calculation of the definite integral of a mathematical function, for which no known integral is known. The former is often the case of response functions in the experimental labors of science and engineering, while the latter is normally the case in the practical investigations of physics, mathematics, and engineering.

Independently of it, the development of numerical methods for integration purposes, a field that belongs to the department of applied mathematics, is based on the simple idea from which it stems, i.e., if ${\displaystyle y(x)=f(x)}$ is a real-valued (the complex-valued case can be treated analogously, by separating it into its real and imaginary parts) continuous function of ${\displaystyle x}$ defined in an interval ${\displaystyle (a,b)}$, its definite integral,

${\displaystyle \int _{a}^{b}f(x)dx=\sum _{x=a}^{x=b}\lim _{\delta x\rightarrow 0}f(x)\delta x=\lim _{\delta x\rightarrow 0}\sum _{x=a}^{x=b}f(x)\delta x\approx \sum _{x=a}^{x=b}f(x)\Delta x}$,

can be calculated approximately as the finite sum of the product ${\displaystyle f(x)\Delta x}$ evaluated at some given points in the interval ${\displaystyle (a,b)}$.

In the case of experimental data, the set of points at which the value of the function is measured is usually not regularly distributed (i.e., the points are not equispaced), so the value of the definite integral must be calculated in the form:

${\displaystyle \int _{a}^{b}f(x)dx=\int _{{x_{0}}=a}^{x_{1}}f(x)dx+\int _{x_{1}}^{x_{2}}f(x)dx+...+\int _{x_{n-2}}^{x_{n-1}}f(x)dx+\int _{x_{n-1}}^{x_{n}=b}f(x)dx}$,

which can be approximated either as:

${\displaystyle \int _{a}^{b}f(x)dx\approx f({x_{0}}=a)({x_{1}}-{x_{0}})+f({x_{1}})({x_{2}}-{x_{1}})+...+f({x_{n-2}})({x_{n-1}}-{x_{n-2}})+f({x_{n-1}})({x_{n}}-{x_{n-1}})}$,

or as:

${\displaystyle \int _{a}^{b}f(x)dx\approx f({x_{1}})({x_{1}}-{x_{0}})+f({x_{2}})({x_{2}}-{x_{1}})+...+f({x_{n-1}})({x_{n-1}}-{x_{n-2}})+f({x_{n}}=b)({x_{n}}-{x_{n-1}})}$.

In the first case, the value of the integral is underestimated (overestimated) in the case of monotonically ascending (descending) functions, since the value of ${\displaystyle f(x)}$ taken in each evaluation is always the lowest (highest) in every subinterval, and hence constituting an absolute lower (upper) bound to the value of the integral, while in the second case, the value of the integral is overestimated (underestimated) in the case of monotonically descending (ascending) functions, since the value of ${\displaystyle f(x)}$ taken in each evaluation is always the highest (lowest) in every subinterval, and hence constituting an absolute upper (lower) bound to the value of the integral.

According to the Mean-Value Theorem of Calculus, the value of a definite integral can also be calculated as:

${\displaystyle \int _{a}^{b}f(x)dx=f(\gamma )(b-a)}$,

for some value ${\displaystyle \gamma }$ in ${\displaystyle (a,b)}$ for which ${\displaystyle f(\gamma )}$ represents the mean value of ${\displaystyle f(x)}$ in ${\displaystyle (a,b)}$, so it is then a better approximation to calculate the definite integral of a set of experimental data as:

${\displaystyle \int _{a}^{b}f(x)dx=\int _{{x_{0}}=a}^{x_{1}}f(x)dx+\int _{x_{1}}^{x_{2}}f(x)dx+...+\int _{x_{n-2}}^{x_{n-1}}f(x)dx+\int _{x_{n-1}}^{x_{n}=b}f(x)dx}$,

${\displaystyle \int _{a}^{b}f(x)dx=f(\gamma _{(0,1)})({x_{1}}-{x_{0}})+f(\gamma _{(1,2)})({x_{2}}-{x_{1}})+...+f(\gamma _{(n-2,n-1)})({x_{n-1}}-{x_{n-2}})+f(\gamma _{(n-1,n)})({x_{n}}-{x_{n-1}})}$,

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{0}})+f({x_{1}})}{2}}({x_{1}}-{x_{0}})+{\frac {f({x_{1}})+f({x_{2}})}{2}}({x_{2}}-{x_{1}})+...+{\frac {f({x_{n-2}})+f({x_{n-1}})}{2}}({x_{n-1}}-{x_{n-2}})+{\frac {f({x_{n-1}})+f({x_{n}})}{2}}({x_{n}}-{x_{n-1}})}$.

For reasons that we shall see later, this is equal to assume a piecewise linear interpolating function between the different points, and the value of the integral so calculated is exact for linear functions (i.e., functions for which its slope changes at constant rate), although it is underestimated for functions for which its slope grows at non-constant rate (i.e., its second derivative is strictly positive in the considered interval), and it is overestimated for functions for which its slope decreases at non-constant rate (i.e., its second derivative is strictly negative in the considered interval). The value so calculated constitutes a better approximation than the lower and upper bounds presented before, and in the case that the second derivative of the function (which can be calculated from the experimental data with the help of second or central differences) changes signs between subintervals, the value is expected to be close to the actual value due to the cancellation of the errors in the approximation of the mean values.

In the case of mathematical functions, there is more information about the function, since it is possible not only to calculate the value of the function at any given point, but also to compute first, second, and higher-order derivatives with any degree of accuracy.

Let us elaborate some mathematical results, going from simple to more elaborate methods:

The main theme in the development of numerical methods, together with the study of the stability (i.e., if a method converges), is the rate of convergence of the method, which studies how many evaluations are needed and the error in the approximation, for non-iterative methods, or how many iterations are needed and how the error is minimized in each iteration, for iterative methods.

In the case of the study of the stability, and as we have seen before, the value of the definite integral of a function ${\displaystyle f(x)}$ defined in an interval ${\displaystyle (a,b)}$,

${\displaystyle \int _{a}^{b}f(x)dx=\sum _{x=a}^{x=b}\lim _{\delta x\rightarrow 0}f(x)\delta x=\lim _{\delta x\rightarrow 0}\sum _{x=a}^{x=b}f(x)\delta x\approx \sum _{x=a}^{x=b}f({x_{k}})\Delta {x_{k}}}$,

can be calculated approximately as the finite sum of the product ${\displaystyle f(x)\Delta x}$ evaluated at some given points in the interval ${\displaystyle (a,b)}$.

In the limit ${\displaystyle \Delta x\rightarrow \delta x\rightarrow 0}$, the finite sum tends to the infinite integral, and so convergence is assured.

In the case of the study of the rate of convergence, one is interested in increasing the accuracy of the approximation, while retaining the number of subintervals, with a minor increase in computational complexity.

The approach used consists normally in using a polynomial approximation for the evaluation of the function ${\displaystyle f(x)}$ in each subinterval, using the information provided by the value of the function at several points in the subinterval.

Let us consider the case of equally-spaced points (although this restriction can be easily lifted):

According to the definition,

${\displaystyle \int _{a}^{b}f(x)dx=\sum _{x=a}^{x=b}\lim _{\delta x\rightarrow 0}f(x)\delta x=\lim _{\delta x\rightarrow 0}\sum _{x=a}^{x=b}f(x)\delta x\approx \sum _{x=a}^{x=b}f({x_{k}})\Delta {x_{k}}=\sum _{x=a}^{x=b}f({x_{k}})({x_{j+1}}-{x_{j}})}$,

with ${\displaystyle k}$ being indicative of the subinterval, ${\displaystyle {x_{k}}}$ being some arbitrary number in every subinterval ${\displaystyle ({x_{j}},{x_{j+1}})}$, with ${\displaystyle j=0,1,2,...,n-1}$, and ${\displaystyle {x_{0}}=a,{x_{n}}=b}$, and ${\displaystyle \Delta {x_{k}}=({x_{j+1}}-{x_{j}})}$, with ${\displaystyle k=1,2,...,n}$, and ${\displaystyle j=k-1}$.

The Mean-Value Theorem of Calculus tells us, that if

${\displaystyle \int _{a}^{b}f(x)dx}$

is the definite integral of ${\displaystyle f(x)}$ in ${\displaystyle (a,b)}$, there exists a value ${\displaystyle \gamma }$ in ${\displaystyle (a,b)}$, such that

${\displaystyle \int _{a}^{b}f(x)dx=f(\gamma )(b-a)}$.

${\displaystyle \int _{a}^{b}f(x)dx}$

is the definite integral of ${\displaystyle f(x)}$ in ${\displaystyle (a,b)}$, this one can also be understood as being composed of the individual contributions

${\displaystyle \int _{a}^{b}f(x)dx=\int _{{x_{0}}=a}^{x_{1}}f(x)dx+\int _{x_{1}}^{x_{2}}f(x)dx+...+\int _{x_{n-2}}^{x_{n-1}}f(x)dx+\int _{x_{n-1}}^{x_{n}=b}f(x)dx}$

for arbitrary values ${\displaystyle {x_{0}}=a,{x_{1}},{x_{2}},...,{x_{n-2}},{x_{n-1}},{x_{n}}=b}$.

Now, applying the Mean-Value Theorem to each individual contribution yields the result:

${\displaystyle \int _{a}^{b}f(x)dx=f(\gamma _{({x_{0}},{x_{1}})})({x_{1}}-{x_{0}})+f(\gamma _{({x_{1}},{x_{2}})})({x_{2}}-{x_{1}})+...+f(\gamma _{({x_{n-2}},{x_{n-1}})})({x_{n-1}}-{x_{n-2}})+f(\gamma _{({x_{n-1}},{x_{n}})})({x_{n}}-{x_{n-1}})}$,

which is exact.

In the particular case that every subinterval is of equal size, i.e., ${\displaystyle ({x_{1}}-{x_{0}})=({x_{2}}-{x_{1}})=...=({x_{n-1}}-{x_{n-2}})=({x_{n}}-{x_{n-1}})=\Delta x}$, then the expression reduces to

${\displaystyle \int _{a}^{b}f(x)dx=\left(f(\gamma _{({x_{0}},{x_{1}})})+f(\gamma _{({x_{1}},{x_{2}})})+...+f(\gamma _{({x_{n-2}},{x_{n-1}})})+f(\gamma _{({x_{n-1}},{x_{n}})})\right)\Delta x}$.

In this way, the calculation of the initial definite integral reduces to the calculation of the mean values

${\displaystyle f(\gamma _{({x_{0}},{x_{1}})}),f(\gamma _{({x_{1}},{x_{2}})}),...,f(\gamma _{({x_{n-2}},{x_{n-1}})}),f(\gamma _{({x_{n-1}},{x_{n}})})}$.

In a first approximation, with only one point,

${\displaystyle f(\gamma _{({x_{0}},{x_{1}})})\approx f({x_{i}}_{({x_{0}},{x_{1}})}),f(\gamma _{({x_{1}},{x_{2}})})\approx f({x_{i}}_{({x_{1}},{x_{2}})}),...,f(\gamma _{({x_{n-2}},{x_{n-1}})})\approx f({x_{i}}_{({x_{n-2}},{x_{n-1}})}),f(\gamma _{({x_{n-1}},{x_{n}})})\approx f({x_{i}}_{({x_{n-1}},{x_{n}})})}$,

with ${\displaystyle {x_{i}}}$ being the value of ${\displaystyle x}$ in the middle of each subinterval, which leads to

${\displaystyle \int _{a}^{b}f(x)dx\approx \left(f({x_{i}}_{({x_{0}},{x_{1}})})+f({x_{i}}_{({x_{1}},{x_{2}})})+...+f({x_{i}}_{({x_{n-2}},{x_{n-1}})})+f({x_{i}}_{({x_{n-1}},{x_{n}})})\right)\Delta x}$.

In a second approximation, with only two points,

${\displaystyle f(\gamma _{({x_{0}},{x_{1}})})\approx {\frac {f({x_{0}})+f({x_{1}})}{2}},f(\gamma _{({x_{1}},{x_{2}})})\approx {\frac {f({x_{1}})+f({x_{2}})}{2}},...,f(\gamma _{({x_{n-2}},{x_{n-1}})})\approx {\frac {f({x_{n-2}})+f({x_{n-1}})}{2}},f(\gamma _{({x_{n-1}},{x_{n}})})\approx {\frac {f({x_{n-1}})+f({x_{n}})}{2}}}$,

with ${\displaystyle {x_{n-1}},{x_{n}}}$ being the value of ${\displaystyle x}$ at the beginning and at the end of each subinterval, which leads to

${\displaystyle \int _{a}^{b}f(x)dx\approx \left(f({x_{0}})+2f({x_{1}})+...+2f({x_{n-1}})+f({x_{n}})\right)\Delta x/2}$.

In a third approximation, with only three points,

${\displaystyle f(\gamma _{({x_{0}},{x_{1}})})\approx {\frac {f({x_{0}})+f({x_{i}}_{({x_{0}},{x_{1}})})+f({x_{1}})}{3}},f(\gamma _{({x_{1}},{x_{2}})})\approx {\frac {f({x_{1}})+f({x_{i}}_{({x_{1}},{x_{2}})})+f({x_{2}})}{3}},...,f(\gamma _{({x_{n-2}},{x_{n-1}})})\approx {\frac {f({x_{n-2}})+f({x_{i}}_{({x_{n-2}},{x_{n-1}})})+f({x_{n-1}})}{3}},f(\gamma _{({x_{n-1}},{x_{n}})})\approx {\frac {f({x_{n-1}})+f({x_{i}}_{({x_{n-1}},{x_{n}})})+f({x_{n}})}{3}}}$,

with ${\displaystyle {x_{n-1}},{x_{i}},{x_{n}}}$ being the value of ${\displaystyle x}$ at the beginning, in the middle, and at the end of each subinterval, which leads to

${\displaystyle \int _{a}^{b}f(x)dx\approx \left(f({x_{0}})+f({x_{i}}_{({x_{0}},{x_{1}})})+2f({x_{1}})+f({x_{i}}_{({x_{1}},{x_{2}})})+2f({x_{2}})+...+2f({x_{n-2}})+f({x_{i}}_{({x_{n-2}},{x_{n-1}})})+2f({x_{n-1}})+f({x_{i}}_{({x_{n-1}},{x_{n}})})+f({x_{n}})\right)\Delta x/3}$.

In a fourth approximation, while still making use of the evaluation of the function ${\displaystyle f(x)}$ at the beginning, in the middle, and at the end of each subinterval, one can use the result that if ${\displaystyle f(\gamma ^{-})}$ and ${\displaystyle f(\gamma ^{+})}$ are estimates for ${\displaystyle f(\gamma )}$, then its arithmetic mean ${\displaystyle \left(f(\gamma ^{-})+f(\gamma ^{+})\right)/2}$ is also another estimate with at least the same accuracy, if not better.

So, adding the results for the first and second approximation, and dividing by two,

${\displaystyle f(\gamma _{({x_{n-1}},{x_{n}})})\approx {\frac {f({x_{i}}_{({x_{n-1}},{x_{n}})})+{\frac {f({x_{n-1}})+f({x_{n}})}{2}}}{2}}={\frac {f({x_{n-1}})+2f({x_{i}}_{({x_{n-1}},{x_{n}})})+f({x_{n}})}{4}}}$,

${\displaystyle \int _{a}^{b}f(x)dx\approx \left(f({x_{0}})+2f({x_{i}}_{({x_{0}},{x_{1}})})+2f({x_{1}})+2f({x_{i}}_{({x_{1}},{x_{2}})})+2f({x_{2}})+...+2f({x_{n-2}})+2f({x_{i}}_{({x_{n-2}},{x_{n-1}})})+2f({x_{n-1}})+2f({x_{i}}_{({x_{n-1}},{x_{n}})})+f({x_{n}})\right)\Delta x/4}$.

Adding the results for the first and third approximation, and dividing by two,

${\displaystyle f(\gamma _{({x_{n-1}},{x_{n}})})\approx {\frac {f({x_{i}}_{({x_{n-1}},{x_{n}})})+{\frac {f({x_{n-1}})+f({x_{i}}_{({x_{n-1}},{x_{n}})})+f({x_{n}})}{3}}}{2}}={\frac {f({x_{n-1}})+4f({x_{i}}_{({x_{n-1}},{x_{n}})})+f({x_{n}})}{6}}}$,

${\displaystyle \int _{a}^{b}f(x)dx\approx \left(f({x_{0}})+4f({x_{i}}_{({x_{0}},{x_{1}})})+2f({x_{1}})+4f({x_{i}}_{({x_{1}},{x_{2}})})+2f({x_{2}})+...+2f({x_{n-2}})+4f({x_{i}}_{({x_{n-2}},{x_{n-1}})})+2f({x_{n-1}})+4f({x_{i}}_{({x_{n-1}},{x_{n}})})+f({x_{n}})\right)\Delta x/6}$.

In practice, one can do no better with only three evaluations in an interval, but the results obtained are simple and accurate enough, even in the case of one single interval.

Let us illustrate the case by means of an example:

Let us suppose, that we wish to calculate the definite integral of the function ${\displaystyle f(x)=exp(x)}$ in the interval ${\displaystyle (0,1)}$, for which we know its exact value, ${\displaystyle F(x)|_{0}^{1}=\int _{0}^{1}exp(x)dx=exp(x)|_{0}^{1}=exp(1)-exp(0)=2.71828-1.00000=1.71828}$.

Let us also keep the problem simple and do the calculations with a single interval, i.e., ${\displaystyle {x_{0}}=a=0.0}$, ${\displaystyle {x_{n}}=b=1.0}$, and ${\displaystyle x_{i}=0.5}$.

So, we have:

First approximation:

${\displaystyle \int _{a}^{b}f(x)dx\approx f(x_{i})(b-a)=exp(0.5)(1.0-0.0)=1.64872}$

This is equal to a relative error of

${\displaystyle error={\frac {1.64872-1.71828}{1.71828}}\times 100=-4.04823\%}$.

Second approximation:

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f(x_{a})+f(x_{b})}{2}}(b-a)={\frac {exp(0.0)+exp(1.0)}{2}}(1.0-0.0)=1.85914}$

This is equal to a relative error of

${\displaystyle error={\frac {1.85914-1.71828}{1.71828}}\times 100=+8.19774\%}$.

Third approximation:

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f(x_{a})+f(x_{i})+f(x_{b})}{3}}(b-a)={\frac {exp(0.0)+exp(0.5)+exp(1.0)}{3}}(1.0-0.0)=1.78900}$

This is equal to a relative error of

${\displaystyle error={\frac {1.85914-1.71828}{1.71828}}\times 100=+4.11575\%}$.

Fourth approximation, first and second terms (linear expansion):

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f(x_{a})+2f(x_{i})+f(x_{b})}{4}}(b-a)={\frac {exp(0.0)+2\times exp(0.5)+exp(1.0)}{4}}(1.0-0.0)=1.75393}$

This is equal to a relative error of

${\displaystyle error={\frac {1.75393-1.71828}{1.71828}}\times 100=+2.07475\%}$.

Fourth approximation, first and third terms (quadratic expansion):

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f(x_{a})+4f(x_{i})+f(x_{b})}{6}}(b-a)={\frac {exp(0.0)+4\times exp(0.5)+exp(1.0)}{6}}(1.0-0.0)=1.71886}$

This is equal to a relative error of

${\displaystyle error={\frac {1.71886-1.71828}{1.71828}}\times 100=+0.0337589\%}$.

In case more accuracy is needed, one can analogously introduce higher-order terms in the expansion of ${\displaystyle f(x)}$ around ${\displaystyle x_{i}}$, or half the integration step in one of the methods considered before.

Let us consider the case, when higher-order terms are considered in the expansion, i.e.,

${\displaystyle f(\gamma _{({x_{n-1}},{x_{n}})})\approx {\frac {f({x_{i}}_{({x_{n-1}},{x_{n}})})+{\frac {f({x_{n-1}})+f({x_{i}}_{1/4})+f({x_{i}}_{({x_{n-1}},{x_{n}})})+f({x_{i}}_{3/4})+f({x_{n}})}{5}}}{2}}={\frac {f({x_{n-1}})+f({x_{i}}_{1/4})+6f({x_{i}}_{({x_{n-1}},{x_{n}})})+f({x_{i}}_{3/4})+f({x_{n}})}{10}}}$,

${\displaystyle \int _{a}^{b}f(x)dx\approx \left(f({x_{0}})+f({x_{1/4}}_{({x_{0}},{x_{1}})})+6f({x_{i}}_{({x_{1}},{x_{2}})})+f({x_{3/4}}_{({x_{0}},{x_{1}})})+2f({x_{1}})+...+2f({x_{n-1}})+f({x_{1/4}}_{({x_{n-1}},{x_{n}})})+6f({x_{i}}_{({x_{n-1}},{x_{n}})})+f({x_{1/4}}_{({x_{n-1}},{x_{n}})})+f({x_{n}})\right)\Delta x/10}$.

Let us illustrate the case by means of an example:

Let us suppose, that we wish to calculate the definite integral of the function ${\displaystyle f(x)=exp(x)}$ in the interval ${\displaystyle (0,1)}$, for which we know its exact value, ${\displaystyle F(x)|_{0}^{1}=\int _{0}^{1}exp(x)dx=exp(x)|_{0}^{1}=exp(1)-exp(0)=2.71828-1.00000=1.71828}$.

Let us also keep the problem simple and do the calculations with two intervals, i.e., ${\displaystyle {x_{0}}=a=0.0}$, ${\displaystyle {x_{n}}=b=1.0}$, ${\displaystyle {x_{1}}=0.5}$, ${\displaystyle {x_{i}}_{({x_{0}},{x_{1}})}=0.25}$ and ${\displaystyle {x_{i}}_{({x_{1}},{x_{2}})}=0.25}$.

Applying second order expansion

${\displaystyle \int _{a}^{b}f(x)dx\approx \left(f({x_{0}})+4f({x_{i}}_{({x_{0}},{x_{1}})})+2f({x_{1}})+4f({x_{i}}_{({x_{1}},{x_{2}})})+f({x_{2}})\right)\Delta x/6}$,

which yields

${\displaystyle \int _{a}^{b}f(x)dx\approx \left(exp(0.0)+4exp(0.25)+2exp(0.5)+4exp(0.75)+exp(1.0)\right)\times 0.5/6=1.71832}$,

which is equal to a relative error of

${\displaystyle error={\frac {1.71832-1.71828}{1.71828}}\times 100=+0.00216456\%}$.

Applying fourth order expansion

${\displaystyle \int _{a}^{b}f(x)dx\approx \left(f(0.0)+f(0.25)+6f(0.50)+f(0.75)+f(1.0)\right)1.0/10}$,

which yields

${\displaystyle \int _{a}^{b}f(x)dx\approx \left(exp(0.0)+7exp(0.25)+2exp(0.5)+7exp(0.75)+exp(1.0)\right)\times 1.0/10}$.

We know from the Calculus of Differences, that any function can be expressed as the polynomial expansion

${\displaystyle f(x)=f({x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{0}})^{2}+...}$

in the case of forward differences, or

${\displaystyle f(x)=f({x_{1}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{1}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{1}})^{2}+...}$

in the case of backward differences, or

${\displaystyle f(x)=f({x_{i}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{i}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{i}})^{2}+...}$

in the case of central differences.

In a first approximation,

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}\left(f({x_{0}})+h({x_{0}})(x-{x_{0}})\right)dx\approx \int _{a}^{b}f({x_{0}})dx=f({x_{0}})(b-a)=f({x_{0}})({x_{1}}-{x_{0}})=f({x_{0}})\Delta x}$

${\displaystyle \int _{a}^{b}h({x_{0}})(x-{x_{0}})dx=h({x_{0}}){\frac {(x-{x_{0}})^{2}}{2}}|_{a}^{b}=h({x_{0}}){\frac {(b-{x_{0}})^{2}-(a-{x_{0}})^{2}}{2}}=h({x_{0}}){\frac {({x_{1}}-{x_{0}})^{2}-({x_{0}}-{x_{0}})^{2}}{2}}=h({x_{0}}){\frac {({x_{1}}-{x_{0}})^{2}}{2}}=h({x_{0}}){\frac {\Delta x^{2}}{2}}\simeq f'({x_{0}}){\frac {\Delta x^{2}}{2}}}$

in the case of forward differences,

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}\left(f({x_{1}})+h({x_{1}})(x-{x_{1}})\right)dx\approx \int _{a}^{b}f({x_{1}})dx=f({x_{1}})(b-a)=f({x_{1}})({x_{1}}-{x_{0}})=f({x_{1}})\Delta x}$

${\displaystyle \int _{a}^{b}h({x_{1}})(x-{x_{1}})dx=h({x_{1}}){\frac {(x-{x_{1}})^{2}}{2}}|_{a}^{b}=h({x_{1}}){\frac {(b-{x_{1}})^{2}-(a-{x_{1}})^{2}}{2}}=h({x_{1}}){\frac {({x_{1}}-{x_{1}})^{2}-({x_{0}}-{x_{1}})^{2}}{2}}=h({x_{1}}){\frac {-({x_{0}}-{x_{1}})^{2}}{2}}=-h({x_{1}}){\frac {\Delta x^{2}}{2}}\simeq -f'({x_{1}}){\frac {\Delta x^{2}}{2}}}$

in the case of backward differences,

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}\left(f({x_{i}})+h({x_{i}})(x-{x_{i}})\right)dx\approx \int _{a}^{b}f({x_{i}})dx=f({x_{i}})(b-a)=f({x_{i}})({x_{1}}-{x_{0}})=f({x_{i}})\Delta x}$

${\displaystyle \int _{a}^{b}h({x_{i}})(x-{x_{i}})dx=h({x_{i}}){\frac {(x-{x_{i}})^{2}}{2}}|_{a}^{b}=h({x_{i}}){\frac {(b-{x_{i}})^{2}-(a-{x_{i}})^{2}}{2}}=h({x_{i}}){\frac {({x_{1}}-{x_{i}})^{2}-({x_{0}}-{x_{i}})^{2}}{2}}=h({x_{i}}){\frac {(\Delta x/2)^{2}-(-\Delta x/2)^{2}}{2}}=h({x_{i}}){\frac {\Delta x^{2}-\Delta x^{2}}{4}}=0}$

in the case of central differences.

So, in the case of evaluating the integral with one single point, the value of it is always underestimated (overestimated) with forward (backward) differences if the value of the slope of the function at the evaluation point is positive, and underestimated (overestimated) with forward (backward) differences if the value of the slope of the function at the evaluation point is negative, being the error in the estimation directly proportional to the slope of the function at the evaluation point, and to one half of the square of the integration step. In the case of evaluating the integral with central differences, the value is exact for linear functions.

In a second approximation,

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}\left(f({x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{0}})+h({x_{0}})(x-{x_{0}})^{2}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx \int _{a}^{b}\left(f({x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{0}})\right)dx=f({x_{0}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}{\frac {({x_{1}}-{x_{0}})^{2}-({x_{0}}-{x_{0}})^{2}}{2}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx f({x_{0}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}{\frac {({x_{1}}-{x_{0}})^{2}}{2}}=f({x_{0}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{2}}({x_{1}}-{x_{0}})={\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})={\frac {f({x_{1}})+f({x_{0}})}{2}}\Delta x}$

${\displaystyle \int _{a}^{b}h({x_{0}})(x-{x_{0}})^{2}dx=h({x_{0}}){\frac {(x-{x_{0}})^{3}}{3}}|_{a}^{b}=h({x_{0}}){\frac {({x_{1}}-{x_{0}})^{3}-({x_{0}}-{x_{0}})^{3}}{3}}=h({x_{0}}){\frac {({x_{1}}-{x_{0}})^{3}}{3}}=h({x_{0}}){\frac {\Delta x^{3}}{3}}\simeq f''({x_{0}}){\frac {\Delta x^{3}}{3}}}$

in the case of forward differences,

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}\left(f({x_{1}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{1}})+h({x_{1}})(x-{x_{1}})^{2}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx \int _{a}^{b}\left(f({x_{1}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{1}})\right)dx=f({x_{1}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}{\frac {({x_{1}}-{x_{1}})^{2}-({x_{0}}-{x_{1}})^{2}}{2}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx f({x_{1}})({x_{1}}-{x_{0}})-{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}{\frac {({x_{1}}-{x_{0}})^{2}}{2}}=f({x_{1}})({x_{1}}-{x_{0}})-{\frac {f({x_{1}})-f({x_{0}})}{2}}({x_{1}}-{x_{0}})={\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})={\frac {f({x_{1}})+f({x_{0}})}{2}}\Delta x}$

${\displaystyle \int _{a}^{b}h({x_{1}})(x-{x_{1}})^{2}dx=h({x_{1}}){\frac {(x-{x_{1}})^{3}}{3}}|_{a}^{b}=h({x_{1}}){\frac {({x_{1}}-{x_{1}})^{3}-({x_{0}}-{x_{1}})^{3}}{3}}=h({x_{1}}){\frac {({x_{1}}-{x_{0}})^{3}}{3}}=h({x_{1}}){\frac {\Delta x^{3}}{3}}\simeq f''({x_{1}}){\frac {\Delta x^{3}}{3}}}$

in the case of backward differences,

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}\left(f({x_{i}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{i}})+h({x_{i}})(x-{x_{i}})^{2}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx \int _{a}^{b}\left(f({x_{i}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{i}})\right)dx=f({x_{i}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}{\frac {({x_{1}}-{x_{i}})^{2}-({x_{0}}-{x_{i}})^{2}}{2}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx f({x_{i}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}{\frac {({x_{1}}-{x_{i}})^{2}-({x_{i}}-{x_{0}})^{2}}{2}}=f({x_{i}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}{\frac {({x_{1}}-{x_{0}})^{2}-({x_{1}}-{x_{0}})^{2}}{8}}=f({x_{i}})({x_{1}}-{x_{0}})=f({x_{i}})\Delta x}$

${\displaystyle \int _{a}^{b}h({x_{i}})(x-{x_{i}})^{2}dx=h({x_{i}}){\frac {(x-{x_{i}})^{3}}{3}}|_{a}^{b}=h({x_{i}}){\frac {({x_{1}}-{x_{i}})^{3}-({x_{0}}-{x_{i}})^{3}}{3}}=h({x_{i}}){\frac {({x_{1}}-{x_{i}})^{3}+({x_{i}}-{x_{0}})^{3}}{3}}=h({x_{i}}){\frac {({x_{1}}-{x_{0}})^{3}}{12}}=h({x_{i}}){\frac {\Delta x^{3}}{12}}\simeq f''({x_{i}}){\frac {\Delta x^{3}}{12}}}$

in the case of central differences.

So, in the case of evaluating the integral with a linear function, there is no difference between forward and backward differences, and the value of the integral is equal to the product of the mean of the values of the function at the beginning and at the end of the interval times the integration step, being the value so calculated underestimated (overestimated) for monotonically increasing (decreasing) functions with a positive (negative) second derivative, the error in the approximation being directly proportional to the second derivative of the function and to the cube of the integration step (i.e., as one increases the number of subintervals, one reduces the deviation proportional to the cube of the number of subintervals). In the case of central differences, the value of the integral is equal to the product of the value of the function in the middle of the interval times the integration step, as in the previous case, the error in the approximation being reduced by a factor of four with relation to the case of forward and backward differences.

In a third approximation,

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}\left(f({x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{0}})^{2}+h({x_{0}})(x-{x_{0}})^{3}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx \int _{a}^{b}\left(f({x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{0}})^{2}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}{\frac {({x_{1}}-{x_{0}})^{3}-({x_{0}}-{x_{0}})^{3}}{3}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}{\frac {({x_{1}}-{x_{0}})^{3}}{3}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{3}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {3f({x_{1}})+3f({x_{0}})+2f({x_{1}})-4f({x_{i}})+2f({x_{0}})}{6}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {5f({x_{0}})-4f({x_{i}})+5f({x_{1}})}{6}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}h({x_{0}})(x-{x_{0}})^{3}dx=h({x_{0}}){\frac {(x-{x_{0}})^{4}}{4}}|_{a}^{b}=h({x_{0}}){\frac {({x_{1}}-{x_{0}})^{4}-({x_{0}}-{x_{0}})^{4}}{4}}=h({x_{0}}){\frac {({x_{1}}-{x_{0}})^{4}}{4}}=h({x_{0}}){\frac {\Delta x^{4}}{4}}\simeq f'''({x_{0}}){\frac {\Delta x^{4}}{4}}}$

in the case of forward differences,

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}\left(f({x_{1}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{1}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{1}})^{2}+h({x_{1}})(x-{x_{1}})^{3}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx \int _{a}^{b}\left(f({x_{1}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{1}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{1}})^{2}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}{\frac {({x_{1}}-{x_{1}})^{3}-({x_{0}}-{x_{1}})^{3}}{3}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})-{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}{\frac {({x_{1}}-{x_{0}})^{3}}{3}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})-{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{3}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {3f({x_{1}})+3f({x_{0}})-2f({x_{1}})+4f({x_{i}})-2f({x_{0}})}{6}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{0}})+4f({x_{i}})+f({x_{1}})}{6}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}h({x_{1}})(x-{x_{1}})^{3}dx=h({x_{1}}){\frac {(x-{x_{1}})^{4}}{4}}|_{a}^{b}=h({x_{1}}){\frac {({x_{1}}-{x_{1}})^{4}-({x_{0}}-{x_{1}})^{4}}{4}}=-h({x_{1}}){\frac {({x_{1}}-{x_{0}})^{4}}{4}}=-h({x_{1}}){\frac {\Delta x^{4}}{4}}\simeq -f'''({x_{1}}){\frac {\Delta x^{4}}{4}}}$

in the case of backward differences,

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}\left(f({x_{i}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{i}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{i}})^{2}+h({x_{i}})(x-{x_{i}})^{3}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx \int _{a}^{b}\left(f({x_{i}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{i}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{i}})^{2}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx f({x_{i}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}{\frac {({x_{1}}-{x_{i}})^{3}-({x_{0}}-{x_{i}})^{3}}{3}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx f({x_{i}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}{\frac {({x_{1}}-{x_{0}})^{3}}{12}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx f({x_{i}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{12}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {12f({x_{i}})+f({x_{1}})-2f({x_{i}})+f({x_{0}})}{12}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+10f({x_{i}})+f({x_{0}})}{12}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}h({x_{i}})(x-{x_{i}})^{3}dx=h({x_{i}}){\frac {(x-{x_{i}})^{4}}{4}}|_{a}^{b}=h({x_{i}}){\frac {({x_{1}}-{x_{i}})^{4}-({x_{0}}-{x_{i}})^{4}}{4}}=h({x_{i}}){\frac {({x_{1}}-{x_{0}})^{4}-({x_{1}}-{x_{0}})^{4}}{64}}=0}$

in the case of central differences.

In a fourth approximation,

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}\left(f({x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{0}})^{2}+{\frac {{\frac {f({x_{1}})-f({x_{i}})}{{x_{1}}-{x_{i}}}}-{\frac {f({x_{i}})-f({x_{0}})}{{x_{i}}-{x_{0}}}}}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{0}})^{3}+h({x_{0}})(x-{x_{0}})^{3}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx \int _{a}^{b}\left(f({x_{0}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{0}})^{2}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}{\frac {({x_{1}}-{x_{0}})^{3}-({x_{0}}-{x_{0}})^{3}}{3}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}{\frac {({x_{1}}-{x_{0}})^{3}}{3}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{3}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {3f({x_{1}})+3f({x_{0}})+2f({x_{1}})-4f({x_{i}})+2f({x_{0}})}{6}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {5f({x_{0}})-4f({x_{i}})+5f({x_{1}})}{6}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}h({x_{0}})(x-{x_{0}})^{3}dx=h({x_{0}}){\frac {(x-{x_{0}})^{4}}{4}}|_{a}^{b}=h({x_{0}}){\frac {({x_{1}}-{x_{0}})^{4}-({x_{0}}-{x_{0}})^{4}}{4}}=h({x_{0}}){\frac {({x_{1}}-{x_{0}})^{4}}{4}}=h({x_{0}}){\frac {\Delta x^{4}}{4}}\simeq f'''({x_{0}}){\frac {\Delta x^{4}}{4}}}$

in the case of forward differences,

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}\left(f({x_{1}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{1}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{1}})^{2}+h({x_{1}})(x-{x_{1}})^{3}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx \int _{a}^{b}\left(f({x_{1}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{1}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{1}})^{2}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}{\frac {({x_{1}}-{x_{1}})^{3}-({x_{0}}-{x_{1}})^{3}}{3}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})-{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}{\frac {({x_{1}}-{x_{0}})^{3}}{3}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+f({x_{0}})}{2}}({x_{1}}-{x_{0}})-{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{3}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {3f({x_{1}})+3f({x_{0}})-2f({x_{1}})+4f({x_{i}})-2f({x_{0}})}{6}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{0}})+4f({x_{i}})+f({x_{1}})}{6}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}h({x_{1}})(x-{x_{1}})^{3}dx=h({x_{1}}){\frac {(x-{x_{1}})^{4}}{4}}|_{a}^{b}=h({x_{1}}){\frac {({x_{1}}-{x_{1}})^{4}-({x_{0}}-{x_{1}})^{4}}{4}}=-h({x_{1}}){\frac {({x_{1}}-{x_{0}})^{4}}{4}}=-h({x_{1}}){\frac {\Delta x^{4}}{4}}\simeq -f'''({x_{1}}){\frac {\Delta x^{4}}{4}}}$

in the case of backward differences,

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}\left(f({x_{i}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{i}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{i}})^{2}+h({x_{i}})(x-{x_{i}})^{3}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx \int _{a}^{b}\left(f({x_{i}})+{\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}({x}-{x_{i}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}({x}-{x_{i}})^{2}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx\approx f({x_{i}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}{\frac {({x_{1}}-{x_{i}})^{3}-({x_{0}}-{x_{i}})^{3}}{3}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx f({x_{i}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{({x_{1}}-{x_{0}})^{2}}}{\frac {({x_{1}}-{x_{0}})^{3}}{12}}}$

${\displaystyle \int _{a}^{b}f(x)dx\approx f({x_{i}})({x_{1}}-{x_{0}})+{\frac {f({x_{1}})-2f({x_{i}})+f({x_{0}})}{12}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {12f({x_{i}})+f({x_{1}})-2f({x_{i}})+f({x_{0}})}{12}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}f(x)dx\approx {\frac {f({x_{1}})+10f({x_{i}})+f({x_{0}})}{12}}({x_{1}}-{x_{0}})}$

${\displaystyle \int _{a}^{b}h({x_{i}})(x-{x_{i}})^{3}dx=h({x_{i}}){\frac {(x-{x_{i}})^{4}}{4}}|_{a}^{b}=h({x_{i}}){\frac {({x_{1}}-{x_{i}})^{4}-({x_{0}}-{x_{i}})^{4}}{4}}=h({x_{i}}){\frac {({x_{1}}-{x_{0}})^{4}-({x_{1}}-{x_{0}})^{4}}{64}}=0}$

in the case of central differences.

The divided differences are:

${\displaystyle {\frac {df(x)}{dx}}\approx {\frac {f({x_{1}})-f({x_{0}})}{{x_{1}}-{x_{0}}}}}$

${\displaystyle {\frac {d^{2}f(x)}{dx^{2}}}\approx {\frac {{\frac {f({x_{1}})-f({x_{i}})}{{x_{1}}-{x_{i}}}}-{\frac {f({x_{i}})-f({x_{0}})}{{x_{i}}-{x_{0}}}}}{{x_{1}}-{x_{0}}}}={\frac {2(f({x_{1}})-2f({x_{i}})+f({x_{0}}))}{({x_{1}}-{x_{0}})^{2}}}}$

${\displaystyle {\frac {d^{3}f(x)}{dx^{3}}}\approx {\frac {{\frac {{\frac {f({x_{1}})-f(({x_{1}}+{x_{i}})/2)}{\frac {{x_{1}}-{x_{0}}}{4}}}-{\frac {f(({x_{1}}+{x_{i}})/2)-f({x_{i}})}{\frac {{x_{1}}-{x_{0}}}{4}}}}{\frac {{x_{1}}-{x_{0}}}{2}}}-{\frac {{\frac {f({x_{i}})-f(({x_{i}}+{x_{0}})/2)}{\frac {{x_{1}}-{x_{0}}}{4}}}-{\frac {f(({x_{i}}+{x_{0}})/2)-f({x_{0}})}{\frac {{x_{1}}-{x_{0}}}{4}}}}{\frac {{x_{1}}-{x_{0}}}{2}}}}{{x_{1}}-{x_{0}}}}={\frac {8(f({x_{1}})-2f(({x_{1}}+{x_{i}})/2)+2f(({x_{i}}+{x_{0}})/2)-f({x_{0}}))}{({x_{1}}-{x_{0}})^{3}}}}$

${\displaystyle {\frac {d^{4}f(x)}{dx^{4}}}\approx {\frac {{\frac {{\frac {{\frac {f({x_{1}})-f(({x_{1}}+{x_{i}})/4)}{\frac {{x_{1}}-{x_{0}}}{8}}}-{\frac {f({x_{1}})-f(({x_{1}}+{x_{i}})/4)}{\frac {{x_{1}}-{x_{0}}}{8}}}}{\frac {{x_{1}}-{x_{0}}}{4}}}-{\frac {f(({x_{1}}+{x_{i}})/2)-f({x_{i}})}{\frac {{x_{1}}-{x_{0}}}{4}}}}{\frac {{x_{1}}-{x_{0}}}{2}}}-{\frac {{\frac {f({x_{i}})-f(({x_{i}}+{x_{0}})/2)}{\frac {{x_{1}}-{x_{0}}}{4}}}-{\frac {f(({x_{i}}+{x_{0}})/2)-f({x_{0}})}{\frac {{x_{1}}-{x_{0}}}{4}}}}{\frac {{x_{1}}-{x_{0}}}{2}}}}{{x_{1}}-{x_{0}}}}={\frac {8(f({x_{1}})-2f(({x_{1}}+{x_{i}})/2)+2f(({x_{i}}+{x_{0}})/2)-f({x_{0}}))}{({x_{1}}-{x_{0}})^{3}}}}$

Lagrange interpolation

One point:

${\displaystyle L_{1}(x_{0},x_{1})=f({\frac {x_{0}+x_{1}}{2}})=f(x_{i})}$

Two points:

${\displaystyle L_{2}(x_{0},x_{1})={\frac {f(x_{0})}{(x_{0}-x_{1})}}(x-x_{1})+{\frac {f(x_{1})}{(x_{1}-x_{0})}}(x-x_{0})}$

Three points:

${\displaystyle L_{3}(x_{0},x_{1})={\frac {f(x_{0})}{(x_{0}-x_{i})(x_{0}-x_{1})}}(x-x_{i})(x-x_{1})+{\frac {f(x_{i})}{(x_{i}-x_{0})(x_{i}-x_{1})}}(x-x_{0})(x-x_{1})+{\frac {f(x_{1})}{(x_{1}-x_{0})(x_{1}-x_{i})}}(x-x_{0})(x-x_{i})}$

Four points:

${\displaystyle L_{4}(x_{0},x_{1})={\frac {f(x_{0})}{(x_{0}-x_{i})(x_{0}-x_{1})}}(x-x_{i})(x-x_{1})+{\frac {f(x_{i})}{(x_{i}-x_{0})(x_{i}-x_{1})}}(x-x_{0})(x-x_{1})+{\frac {f(x_{1})}{(x_{1}-x_{i})(x_{1}-x_{0})}}(x-x_{i})(x-x_{0})}$

Five points:

${\displaystyle L_{5}(x_{0},x_{1})={\frac {f(x_{0})}{(x_{0}-x_{i})(x_{0}-x_{1})}}(x-x_{i})(x-x_{1})+{\frac {f(x_{i})}{(x_{i}-x_{0})(x_{i}-x_{1})}}(x-x_{0})(x-x_{1})+{\frac {f(x_{1})}{(x_{1}-x_{i})(x_{1}-x_{0})}}(x-x_{i})(x-x_{0})}$

Six points:

${\displaystyle L_{6}(x_{0},x_{1})={\frac {f(x_{0})}{(x_{0}-x_{i})(x_{0}-x_{1})}}(x-x_{i})(x-x_{1})+{\frac {f(x_{i})}{(x_{i}-x_{0})(x_{i}-x_{1})}}(x-x_{0})(x-x_{1})+{\frac {f(x_{1})}{(x_{1}-x_{i})(x_{1}-x_{0})}}(x-x_{i})(x-x_{0})}$

Seven points:

${\displaystyle L_{7}(x_{0},x_{1})={\frac {f(x_{0})}{(x_{0}-x_{i})(x_{0}-x_{1})}}(x-x_{i})(x-x_{1})+{\frac {f(x_{i})}{(x_{i}-x_{0})(x_{i}-x_{1})}}(x-x_{0})(x-x_{1})+{\frac {f(x_{1})}{(x_{1}-x_{i})(x_{1}-x_{0})}}(x-x_{i})(x-x_{0})}$

One point:

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}(L_{1}(x)+h_{1}(x))dx=\int _{a}^{b}(f(x_{i})+1h_{1}(x-x_{i}))dx}$

${\displaystyle \int _{a}^{b}f(x)dx=f(x_{i})(x_{1}-x_{0})+h_{1}{\frac {(x_{1}-x_{i})^{2}-(x_{0}-x_{i})^{2}}{2}}}$

${\displaystyle \int _{a}^{b}f(x)dx=f(x_{i})(x_{1}-x_{0})}$

${\displaystyle \int _{a}^{b}f(x)dx=f(x_{i})\Delta x}$

Two points:

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}(L_{2}(x)+h_{2}(x))dx=\int _{a}^{b}\left({\frac {f(x_{0})}{(x_{0}-x_{1})}}(x-x_{1})+{\frac {f(x_{1})}{(x_{1}-x_{0})}}(x-x_{0})+2h_{2}(x-x_{i})^{2}\right)dx}$

${\displaystyle \int _{a}^{b}f(x)dx={\frac {f(x_{0})}{(x_{0}-x_{1})}}{\frac {(x_{1}-x_{1})^{2}-(x_{0}-x_{1})^{2}}{2}}+{\frac {f(x_{1})}{(x_{1}-x_{0})}}{\frac {(x_{1}-x_{0})^{2}-(x_{0}-x_{0})^{2}}{2}}+2h_{2}{\frac {(x_{1}-x_{i})^{3}-(x_{0}-x_{i})^{3}}{3}}}$

${\displaystyle \int _{a}^{b}f(x)dx={\frac {f(x_{0})}{(x_{0}-x_{1})}}{\frac {-(x_{0}-x_{1})^{2}}{2}}+{\frac {f(x_{1})}{(x_{1}-x_{0})}}{\frac {(x_{1}-x_{0})^{2}}{2}}+2h_{2}{\frac {(x_{1}-x_{0})^{3}-(x_{0}-x_{1})^{3}}{24}}}$

${\displaystyle \int _{a}^{b}f(x)dx={\frac {-f(x_{0})}{2}}(x_{0}-x_{1})+{\frac {f(x_{1})}{2}}(x_{1}-x_{0})+2h_{2}{\frac {(x_{1}-x_{0})^{3}+(x_{1}-x_{0})^{3}}{24}}}$

${\displaystyle \int _{a}^{b}f(x)dx={\frac {f(x_{0})}{2}}(x_{1}-x_{0})+{\frac {f(x_{1})}{2}}(x_{1}-x_{0})+4h_{2}{\frac {(x_{1}-x_{0})^{3}}{24}}}$

${\displaystyle \int _{a}^{b}f(x)dx={\frac {f(x_{0})+f(x_{1})}{2}}(x_{1}-x_{0})+h_{2}{\frac {(x_{1}-x_{0})^{3}}{6}}}$

${\displaystyle \int _{a}^{b}f(x)dx={\frac {f(x_{0})+f(x_{1})}{2}}\Delta x+h_{2}{\frac {\Delta x^{3}}{6}}}$

${\displaystyle \int _{a}^{b}f(x)dx=(f(x_{0})+f(x_{1})){\frac {\Delta x}{2}}+h_{2}{\frac {\Delta x^{3}}{6}}}$

Three points:

${\displaystyle \int _{a}^{b}f(x)dx=\int _{a}^{b}(L_{3}(x)+h_{3}(x))dx=\int _{a}^{b}(L_{3,1}(x)+L_{3,2}(x)+L_{3,3}(x)+h_{3}(x))dx}$

{\displaystyle {\begin{aligned}\int _{a}^{b}f(x)dx&=\int _{a}^{b}\left({\frac {f(x_{0})}{(x_{0}-x_{i})(x_{0}-x_{1})}}(x-x_{i})(x-x_{1})\right)dx\\&+\int _{a}^{b}\left({\frac {f(x_{i})}{(x_{i}-x_{0})(x_{i}-x_{1})}}(x-x_{0})(x-x_{1})\right)dx\\&+\int _{a}^{b}\left({\frac {f(x_{1})}{(x_{1}-x_{0})(x_{1}-x_{i})}}(x-x_{0})(x-x_{i})\right)dx\\&+\int _{a}^{b}h_{3}(x)(x-x_{i})^{3}dx\end{aligned}}}

{\displaystyle {\begin{aligned}\int _{a}^{b}f(x)dx&=\int _{a}^{b}\left({\frac {f(x_{0})}{(x_{0}-x_{i})(x_{0}-x_{1})}}(x^{2}-xx_{i}-xx_{1}+x_{i}x_{1})\right)dx\\&+\int _{a}^{b}\left({\frac {f(x_{i})}{(x_{i}-x_{0})(x_{i}-x_{1})}}(x^{2}-xx_{0}-xx_{1}+x_{0}x_{1})\right)dx\\&+\int _{a}^{b}\left({\frac {f(x_{1})}{(x_{1}-x_{0})(x_{1}-x_{i})}}(x^{2}-xx_{0}-xx_{i}+x_{0}x_{i})\right)dx\\&+\int _{a}^{b}h_{3}(x)(x-x_{i})^{3}dx\end{aligned}}}

{\displaystyle {\begin{aligned}\int _{a}^{b}f(x)dx&=\int _{a}^{b}\left({\frac {f(x_{0})}{(x_{0}-x_{i})(x_{0}-x_{1})}}(x^{2}-(x_{i}+x_{1})x+x_{i}x_{1})\right)dx\\&+\int _{a}^{b}\left({\frac {f(x_{i})}{(x_{i}-x_{0})(x_{i}-x_{1})}}(x^{2}-(x_{0}+x_{1})x+x_{0}x_{1})\right)dx\\&+\int _{a}^{b}\left({\frac {f(x_{1})}{(x_{1}-x_{0})(x_{1}-x_{i})}}(x^{2}-(x_{0}+x_{i})x+x_{0}x_{i})\right)dx\\&+\int _{a}^{b}h_{3}(x)(x-x_{i})^{3}dx\end{aligned}}}

{\displaystyle {\begin{aligned}\int _{a}^{b}f(x)dx&={\frac {f(x_{0})}{(x_{0}-x_{i})(x_{0}-x_{1})}}({\frac {x_{1}^{3}-x_{0}^{3}}{3}}-(x_{i}+x_{1}){\frac {x_{1}^{2}-x_{0}^{2}}{2}}+x_{i}x_{1}(x_{1}-x_{0}))\\&+{\frac {f(x_{i})}{(x_{i}-x_{0})(x_{i}-x_{1})}}({\frac {x_{1}^{3}-x_{0}^{3}}{3}}-(x_{0}+x_{1}){\frac {x_{1}^{2}-x_{0}^{2}}{2}}+x_{0}x_{1}(x_{1}-x_{0}))\\&+{\frac {f(x_{1})}{(x_{1}-x_{0})(x_{1}-x_{i})}}({\frac {x_{1}^{3}-x_{0}^{3}}{3}}-(x_{0}+x_{i}){\frac {x_{1}^{2}-x_{0}^{2}}{2}}+x_{0}x_{i}(x_{1}-x_{0}))\\&+h_{3}{\frac {(x_{1}-x_{i})^{4}-(x_{0}-x_{i})^{4}}{4}}\end{aligned}}}

{\displaystyle {\begin{aligned}\int _{a}^{b}f(x)dx&={\frac {2f(x_{0})}{(x_{0}-x_{1})(x_{0}-x_{1})}}({\frac {x_{1}^{3}-x_{0}^{3}}{3}}-({\frac {x_{0}+x_{1}}{2}}+x_{1}){\frac {x_{1}^{2}-x_{0}^{2}}{2}}+{\frac {x_{0}+x_{1}}{2}}x_{1}(x_{1}-x_{0}))\\&+{\frac {4f(x_{i})}{(x_{1}-x_{0})(x_{0}-x_{1})}}({\frac {x_{1}^{3}-x_{0}^{3}}{3}}-(x_{0}+x_{1}){\frac {x_{1}^{2}-x_{0}^{2}}{2}}+x_{0}x_{1}(x_{1}-x_{0}))\\&+{\frac {2f(x_{1})}{(x_{1}-x_{0})(x_{1}-x_{0})}}({\frac {x_{1}^{3}-x_{0}^{3}}{3}}-(x_{0}+{\frac {x_{0}+x_{1}}{2}}){\frac {x_{1}^{2}-x_{0}^{2}}{2}}+x_{0}{\frac {x_{0}+x_{1}}{2}}(x_{1}-x_{0}))\\&+h_{3}{\frac {(x_{1}-x_{i})^{4}-(x_{0}-x_{i})^{4}}{4}}\end{aligned}}}