# Calculating the antiderivative numerically

In the standard literature topics like numerical differentiation and numerical integration are usually discussed in detail. However, numerical integration is not the same as calculating the (true) antiderivative numerically.

What is the reason nobody is discussing this topic? Is there simply no application for this?

Note that the antiderivative is unique up to a constant.

To expand:

The function $$f(x)=x$$ is given at five discrete points (Legendre-Gauss)

$$x_i= \begin{pmatrix} -0.906 & -0.538 & 0.000 & 0.538 & 0.906 \end{pmatrix}^\text{T}$$

with function values

$$f_{i}= \begin{pmatrix} -0.906 & -0.538 & 0.000 & 0.538 & 0.906 \end{pmatrix}^\text{T}$$

$$\omega_{j}= \begin{pmatrix} 0.237& 0.479& 0.569& 0.479& 0.237 \end{pmatrix}$$

and the related derivative matrix at these points

$$D_{ij}=\begin{pmatrix} -5.067&7.702&-4.044&1.960&-0.552\\ -0.960&-0.758&2.403&-0.929&0.244\\ 0.301&-1.435&-0.000&1.435&-0.301\\ -0.244&0.929&-2.403&0.758&0.960\\ 0.552&-1.960&4.044&-7.702&5.067\\ \end{pmatrix}$$

and the related antiderivative matrix at these points

$$A_{ij}=\begin{pmatrix} -0.109&-0.559&-0.262&0.030&-0.006\\ 0.029&-0.281&-0.334&0.062&-0.015\\ 0.000&0.000&0.000&0.000&0.000\\ 0.015&-0.062&0.334&0.281&-0.029\\ 0.006&-0.030&0.262&0.559&0.109\\ \end{pmatrix}$$.

Note that

$$A_{ij} \ne D_{ij}^{-1}$$.

Now it is possible to define following numerical operations:

$$I=\omega_{j} f_i = 0.000$$

Numerical differentiation

$$\partial f_i=D_{ij} f_i = \begin{pmatrix} 1.000 & 1.000 & 1.000 & 1.000 & 1.000 \end{pmatrix}^\text{T}$$

Numerical antidifferentiation

$$F_i=A_{ij} f_i = \begin{pmatrix} 0.411 & 0.145& 0.000& 0.145& 0.411 \end{pmatrix}^\text{T}$$

Note that applying the Fundamental theorem of calculus to this function

$$I = F(-1) - F(1)=0.000$$

would give you a similar result to Gauss quadrature.

• Just to clarify, from the antiderivative graph you show, I get the feeling that the the numerical antiderivative $\hat{G}(x)$ you compute is an approximation to $G(x) = \int_{0}^{x} f(s)\text{d}s$. Is that right? May 8, 2021 at 6:38
• @AbdullahAliSivas Yes it is the antiderivative of the polynomial approximation. The calculation of the antiderivative matrix is similar to the calculation of the derivation matrix, however the other way round. I am curious no literature is discussing this topic. May 8, 2021 at 7:23
• It is exact up to roundofferrors in this case. May 8, 2021 at 7:47
• The basic answer is that for orthogonal polynomials, the integration weights are as good you can get and it's a diagonal matrix. I'll expand that later into an answer, because it's a good question. May 8, 2021 at 8:42
• See also scicomp.stackexchange.com/questions/21869/… on plotting a numerical anti-derivative or primitive function. May 8, 2021 at 8:44

Antiderivatives are considered through numerical integration. The following antiderivative

$$\int f(x)\, dx = G(x) + C\, ,$$

can be rewritten as

$$\frac{d G(x)}{dx} = f(x)\, .$$

And then solved numerically.

Ok, here is the answer promised in the comment section. I thought I would have more time to elaborate, but as usual, that was not the case, so I'll just add some thoughts

First of all, there is no obvious definition of the antiderivative matrix $$A$$, because the derivative matrix $$D$$ is one order short to full rank. This is akin to the fact that he antiderivative has a an integration constant $$c$$. So, claiming $$AD=I$$ od $$DA = I$$ won' t work.

There is a method called rectangular spectral collocation (google!), which takes this into account and from the first defines a rectangular derivative matrix of size $$N \times N-1$$. Moreover, in this context, people use integration matrices as preconditioner, which allow to avoid the influence badly conditioned derivative matrices. These matrices, however, are defined as a solution to a Birkhoff interpolation problem. But this just as a pointer whether integration matrices are used in the literature.

Now to your question, 'why they are not used more'. This is quite subjective, but I'd say, they're not often needed. Take your case, numerical integration: Instead of applying a matrix (which takes $$\mathcal O(N^2)$$ and then making use of the fundamental theorem, one can simply use Gaussian or Newton-Cotes integration, which is at least as accurate. For the special functions you mention in your answer, there are more appropriate methods, but even if one wanted to go with numerical integration, one could use standard integration methods as well.

One useful application is the calculation of antiderivatives of nonelementary integrable functions. They are obviously only approximations.

Error Integral:

$$\text{erf}(\tilde{x})=\int e^{-x^2}\,dx$$

Trigonometric Integral:

$$\text{si}(\tilde{x})=\int \frac{\sin x}{x}\,dx$$

• I think that for these examples asymptotic expansions are commonly the way to go. May 10, 2021 at 18:03