# A Integrating definite Heaviside function

1. Oct 12, 2016

### bfeinberg

I am trying to integrate the following triple integral, which has a heaviside function in the inner most integral:

$$\frac{16}{c_{4}^{4}} \int_{0}^{c_{4}} c_{3}dc_{3} \int_{c_{3}}^{c_{4}} \frac{dc_{2}}{c_{2}} \int_{0}^{c_{2}}f(x)\left ( 1-H\left ( x-\left ( c_{4}-a \right ) \right ) \right )dx$$

where f(x)=x. I know $c_{2}>0, c_{3}>0 , c_{4}>0, x>0 , a>0 ,c_{4}>a$

I get the right answer (which I know already) using symbolic integration and the heaviside function in Matlab, which is:

$$1-4\frac{a^{2}}{c_{4}^{2}}+4\frac{a^{3}}{c_{4}^{3}}-\frac{a^{4}}{c_{4}^{4}}$$

However, it is not clear to me how to do this manually? I would like to know because I need to integrate this numerically for cases where f(x) is a more complicated function.

Last edited by a moderator: Oct 12, 2016
2. Oct 12, 2016

### pasmith

As with any function defined by different formulae on different subdomains, you need to integrate over each subdomain separately. Thus $$\int_a^b f(x)~(1 - H(x - c))\,dx = \begin{cases} 0 & c \leq a, \\ \int_a^c f(x)\,dx & a < c \leq b, \\ \int_a^b f(x)\,dx & b < c. \end{cases}$$

3. Oct 12, 2016

### bfeinberg

Thanks for the reply. Unfortunately, this still doesn't seem to be giving me the right answer...? It is always true that $a<c \leq b$ .

$$\frac{16}{c_{4}^{4}} \int_{0}^{c_{4}} c_{3}dc_{3} \int_{c_{3}}^{c_{4}} \frac{dc_{2}}{c_{2}} \int_{0}^{c_{4}-a}f(x)dx$$

This gives me, upon my attempt at integration,

$$2 \frac{a^{2}}{{c_{4}}^2} - 4\frac{a}{c_{4}} + 2$$

which unfortunately is not the same as the literature answer.

4. Oct 15, 2016

### pasmith

You can, of course, do the entire thing numerically because your integrand is just $$f(x)(1 - H(x - (c_4 - a))) = \begin{cases} f(x), & 0 < x < c_4 - a \\ 0, & c_4 - a \leq x < c_2\end{cases}$$ which is no more difficult to evaluate numerically than $f(x)$ itself.

Doing it manually requires us always to check where the limits of the integral fall in relation to $c_4 - a$, which given your constraints must lie between 0 and $c_4$, ie. within the limits of the outermost integral and therefore conceivably within the limits of the inner integrals.

Thus for $f(x) = x$ we find that the innermost integral is $$\int_0^{c_2} x(1 - H(x - (c_4 - a)))\,dx = \frac12 \min\{(c_4 - a)^2, c_2^2\}.$$ The next integral out is then $$\int_{c_3}^{c_4} \frac{1}{2c_2} \min\{(c_4 - a)^2, c_2^2\}\,dc_2.$$ Hence if $c_3 < c_4 - a$ then $$\int_{c_3}^{c_4} \frac{1}{2c_2} \min\{(c_4 - a)^2, c_2^2\}\,dc_2 = \int_{c_3}^{c_4 - a} \frac{1}{2c_2} c_2^2\,dc_2 + \int_{c_4 - a}^{c_4} \frac{1}{2c_2} (c_4 - a)^2\,dc_2 \\ = \frac14 ((c_4 - a)^2 - c_3^2) + \frac{(c_4 - a)^2}{2} \log \left( \frac{c_4}{c_4 - a}\right)$$ but if $c_4 - a < c_3$ then $$\int_{c_3}^{c_4} \frac{1}{2c_2} \min\{(c_4 - a)^2, c_2^2\}\,dc_2 = \frac{(c_4 - a)^2}{2} \log \left( \frac{c_4}{c_3}\right).$$ Now we can do the outermost integral which is $$\frac{16}{c_4^4} \int_0^{c_4 - a} \frac{c_3}4 ((c_4 - a)^2 - c_3^2) + \frac{c_3(c_4 - a)^2}{2} \log \left( \frac{c_4}{c_4 - a}\right)\,dc_3 + \frac{16}{c_4^4} \int_{c_4 - a}^{c_4}\frac{c_3(c_4 - a)^2}{2} \log \left( \frac{c_4}{c_3}\right)\,dc_3.$$