What is the general formula for $\int h(x)$ if $h(x) = f(x)g(x)$?

102 Views Asked by At

The product rule is great for the derivatives, but I'm wondering if there is a similar general rule for integration when you have a function $h(x)$ that is the product of two functions that you know the integral for.

The context of this question is that I have a normal distribution and a linear function, and I want to know the integral of their product.

For example:

$$\text{NORMAL} = \mathcal{N}(100,12) = \frac{1}{\sqrt{2 \pi \cdot 12^2}}e^{-\frac{(x-100)^2}{2\cdot 12^2}}$$

$$\text{OTHER} = 12.95x + 26$$

I want the general way to find the integral of the product of two functions such as this.

A note on how this is being used, because it limits the types of solutions that are acceptable for my situation:

This formula is going to be implemented in a computer program, so all functions that I use must either be able to be evaluated with arithmetic, or have a convergent sum representation.

I have an implementation for the CDF for a normal distribution already created, so the integral of the normal function is something which I have available to use.

Here's an example of the limitations:

$$u = f(x | \mu,\sigma^2) = \frac{1}{\sqrt{2 \pi \cdot \sigma^2}}e^{-\frac{(x-\mu)^2}{2\cdot \sigma^2}}$$

$$v' = g(x|a,b) = ax + b$$

$$h(x) = f(x) \cdot g(x)$$

From integration by parts, we know that:

$$\int{uv' \,dx} = uv - \int{u'v \,dx}$$

So we know that:

$$v = \int{ax+b \,dx} = \frac{ax^2}{2} + bx + C$$

$$u' = \frac{(\mu - x)}{\sigma^2 \cdot \sqrt{2 \pi \cdot \sigma^2}}e^{-\frac{(x-\mu)^2}{2\cdot \sigma^2}}$$

Now if I use integration by parts, I end up with this:

$$\int h(x) = \frac{\frac{ax^2}{2}+bx + C}{\sqrt{2 \pi \cdot \sigma^2}}e^{-\frac{(x-\mu)^2}{2\cdot \sigma^2}} - \int{\frac{(\mu - x)(\frac{ax^2}{2}+bx + C)}{\sigma^2 \cdot \sqrt{2 \pi \cdot \sigma^2}}e^{-\frac{(x-\mu)^2}{2\cdot \sigma^2}} \,dx}$$

But the integral on the right is just as difficult to calculate, and doesn't conform to the existing $\text{erf}$ I have already implemented for the normal distribution.

If I use the opposite form:

$$v' = f(x | \mu,\sigma^2) = \frac{1}{\sqrt{2 \pi \cdot \sigma^2}}e^{-\frac{(x-\mu)^2}{2\cdot \sigma^2}}$$

$$u = g(x|a,b) = ax + b$$

$$v = \frac{1}{2}\left[1 + \operatorname{erf}\left( \frac{x-\mu}{\sigma\sqrt{2}}\right)\right]$$

$$u' = a$$

Then:

$$\int h(x) = \frac{ax+b}{2}\left[1 + \operatorname{erf}\left( \frac{x-\mu}{\sigma\sqrt{2}}\right)\right] - \int{\frac{a}{\sqrt{2 \pi \cdot \sigma^2}}e^{-\frac{(x-\mu)^2}{2\cdot \sigma^2}}}$$

Is certainly simpler, but runs into the same problem of calculating the integral on the right.

Note that $a$, $b$, $\mu$, and $\sigma$ may all have arbitrary values, so I can't simplify them out of the formula.

EDIT: I believe I've found a workable answer that satisfies my problem, but would appreciate it if someone who understands the math better could check it for me:

$$\int h(x) = \frac{ax+b}{2}\left[1 + \operatorname{erf}\left( \frac{x-\mu}{\sigma\sqrt{2}}\right)\right] - \frac{a}{2}\left[1 + \operatorname{erf}\left( \frac{x-\mu}{\sigma\sqrt{2}}\right)\right] + \frac{1}{2}\left[1 + \operatorname{erf}\left( \frac{x-\mu}{\sigma\sqrt{2}}\right)\right]$$

Simplified:

$$\int h(x) = \frac{ax-a+b+1}{2}\left[1 + \operatorname{erf}\left( \frac{x-\mu}{\sigma\sqrt{2}}\right)\right]$$

Or:

$$\int h(x) = (ax-a+b+1) \cdot \frac{1}{2}\left[1 + \operatorname{erf}\left( \frac{x-\mu}{\sigma\sqrt{2}}\right)\right]$$

Or:

$$\int h(x) = (ax-a+b+1) \cdot \Phi (x)$$

2

There are 2 best solutions below

9
On BEST ANSWER

This is surely a duplicate in spirit, but it's apparently tricky to find a suitable question to redirect you to.

There is indeed an analogue of the product rule for integration: If $u, v$ are functions of $x$, we can write the usual product rule as $$(uv)' = u v' + u' v,$$ and integrating gives $$u v = \int u v' \,dx + \int u' v \,dx = \int u \,dv + \int v \,du$$ Rearranging gives the integration by parts formula: $$\int u v' \,dx = uv - \int u' v \,dx .$$ We can see that if we wish to apply this formula, we must in particular integrate one of the factors of the original product.

To integrate our particular function, however, we don't need to use integration by parts: By making an appropriate affine change of variable $x \rightsquigarrow u$, we can rewrite the product $$\frac{1}{\sqrt{2 \pi} \sigma} \exp\left[-\frac{(x - \mu)^2}{2 \sigma^2}\right] \cdot (a x + b)$$ as $$A u e^{-u^2} + B e^{-u^2}$$ for some constants $A, B$. The first term can be integrated via substitution, but the second term has no closed-form antiderivative; often we express that antiderivative in terms of the error function, $$\operatorname{erf}(u) = \frac{2}{\sqrt \pi} \int_0^u e^{-t^2} dt.$$

Putting this all together we find $$\begin{multline}\color{#bf0000}{\int \frac{1}{\sqrt{2 \pi} \sigma} \exp\left[-\frac{(x - \mu)^2}{2 \sigma^2}\right] \cdot (a x + b) \,dx} \\ \color{#bf0000}{= \frac{1}{2} (a \mu + b) \operatorname{erf} \left(\frac{x - \mu}{\sqrt{2} \sigma}\right) - \frac{a \sigma}{\sqrt{2 \pi}} \exp \left[- \frac{(x - \mu)^2}{2 \sigma^2}\right] + C} . \end{multline}$$ We can alternatively write the second term on the right-hand side in your notation as $-a \sigma^2 f(x | \mu, \sigma^2)$.

0
On

In the particular case of $f(x)=u'(v(x))$ and $g(x)=v'(x)$ we have

$$\int h(x)dx = \int f(x)g(x)dx=\int u'(v(x))v'(x)dx=u(v(x)) +C$$

and as a more general method from the product rule for derivative

$$[u(x)v(x)]'=u'(x)v(x)+u(x)v'(x)$$

we can show that the following holds

$$\int u'(x)v(x)dx =u(x)v(x) -\int u(x)v'(x)dx$$

which is the well known formula for integration by parts.