Problem
I need to numerically evaluate the integral $$\int_{t-\Delta t/2}^{t+\Delta t/2} f(\tau) g(\tau) \mathrm{d}\tau,$$ where
- $f: \mathbb{R} \to \mathbb{R}$ is known analytically, but
- only the numerical value of $$\int_{t-\Delta t/2}^{t+\Delta t/2} g(\tau) \mathrm{d}\tau$$ can be obtained (for any $t$), and
- $\Delta t$ is “relatively small”.
Questions
How can I obtain a numerical value of the integral $\int_{t-\Delta t/2}^{t+\Delta t/2} f(\tau) g(\tau) \mathrm{d}\tau$ given these limitations? Alternatively, how could I obtain a numerical value of the derivative $\frac{\mathrm{d}}{\mathrm{d}t} \int_{t-\Delta t/2}^{t+\Delta t/2} f(\tau) g(\tau) \mathrm{d}\tau$?
Idea
If I approximate the integral over the product $f(\tau)g(\tau)$ by a midpoint Riemann “sum”, I obtain $$\int_{t-\Delta t/2}^{t+\Delta t/2} f(\tau) g(\tau) \mathrm{d}\tau \approx f(t)g(t)\Delta t.$$ Additionally, I could (not sure if it’s correct) approximate the derivative of the product of the integrals over $f(t)$ and $g(t)$ as $$\frac{\mathrm{d}}{\mathrm{d}t} \left(\int_{t-\Delta t/2}^{t+\Delta t/2} f(\tau) \mathrm{d}\tau \int_{t-\Delta t/2}^{t+\Delta t/2} g(\tau) \mathrm{d}\tau \right) \stackrel{?}{\approx} \frac{1}{\Delta t} f(t)\Delta t g(t)\Delta t = f(t)g(t)\Delta t.$$
But I am not sure:
- Is the second approximation reasonable?
- If so, does it imply that I can approximate the integral over $f(\tau)g(\tau)$ as $$\int_{t-\Delta t/2}^{t+\Delta t/2} f(\tau) g(\tau) \mathrm{d}\tau \stackrel{?}{\approx} \frac{\mathrm{d}}{\mathrm{d}t} \left(\int_{t-\Delta t/2}^{t+\Delta t/2} f(\tau) \mathrm{d}\tau \int_{t-\Delta t/2}^{t+\Delta t/2} g(\tau) \mathrm{d}\tau \right),$$ where I integrate $f(\tau)$ numerically and obtain the numerical value of $\int_{t-\Delta t/2}^{t+\Delta t/2} g(\tau) \mathrm{d}\tau$?
That is not how you differentiate the product of two things, so... no.
You can however apply the midpoint rule to see that you have an approximation of $g(t)$, given by
$$g(t)\approx\tilde g(t)=\frac1{\Delta t}\int_{t-\Delta t/2}^{t+\Delta t/2}g(\tau)~\mathrm d\tau.$$
More precisely, we expect $g(t)=\tilde g(t)+\mathcal O(\Delta t)$ if $g$ is continuously twice differentiable. You may verify this by substituting $g(\tau)$ with $g(t)+g'(t)(\tau-t)+\mathcal O((\tau-t)^2)$.
From this, we may then approximate
$$I=\int_{t-\Delta t/2}^{t+\Delta t/2}f(\tau)g(\tau)~\mathrm d\tau\approx\int_{t-\Delta t/2}^{t+\Delta t/2}f(\tau)\tilde g(\tau)~\mathrm d\tau$$
which has an error of $\mathcal O(\Delta t^2)$. Now just use a suitable integral approximation to keep an error of $\mathcal O(\Delta t^2)$.