Does $\int\limits_a^b \left(\sum\limits_{k=1}^L \max(x,a_k)\right)^m \text{d}x$ has closed form? I have this integral that I need to solve:
$\int\limits_a^b \left(\sum\limits_{k=1}^L \max(x,a_k)\right)^m \text{d}x$ for some constant $a_k\in\mathbb{R}, k=\{1,\dots,L\}$.
 A: As I mention in the comments, it might make the problem a little easier to solve if you use the fact that $$\text{Max}(a,b) = \frac{a+b+|a-b|}{2} = \frac{a+b+\sqrt{(a-b)^2}}{2}$$ for real numbers. Just be careful to use the principal square root. (I haven't actually checked that this works, and if there is some obvious flaw feel free to point it out... I looked at the problem briefly)
A: I don't know if this is the idea, but if you define $c$ as a sorted $a$ from low to high it is clear that
$\int_a^b(\sum_{k=1}^Lmax(x,c_k))^2dx$
is the same as asked. Now we can split up the integral between each successive value of $c$. For now let's assume $a<c_1<c_L<b$, the extension to relaxing this constraint is not difficult. Then we get to:
$\int_a^{c_1}(\sum_{k=1}^Lc_k)^2dx + \int_{c_1}^{c_2}((x+\sum_{k=2}^Lc_k)^2dx+...+\int_{C_{L-1}}^{c_L}((L-1)x+c_L)^2dx + \int_{c_L}^b(Lx)^2dx$
These sums are just constants, if we name these $d_i = \sum_{k=i}^Lc_k$ we get to:
$\int_a^{c_1}(d_1)^2dx + \int_{c_1}^{c_2}((x+d_2)^2dx+...+\int_{C_{L-1}}^{c_L}((L-1)x+d_L)^2dx + \int_{c_L}^b((Lx)^2dx$
which equates to:
$\int_a^{c_1}d_1^2dx + \int_{c_1}^{c_2}(x^2+2d_2x + d_2^2)dx+...+\int_{C_{L-1}}^{c_L}((L-1)^2x^2+2(L-1)d_L+d_L^2)dx + \int_{c_L}^b((Lx)^2dx$
Splitting up in the parts that don't contain $x$, $I_0$, those that contain $x$, $I_1$ and those that contain $x^2$, $I_2$ we get to:
$I_0 = \int_a^{c_1}d_1^2dx +\int_{c_1}^{c_2}d_2^2dx + ... +\int_{c_{L-1}}^{c_L}d_L^2dx=(c_1-a)d_1^2+(c_2-c_1)d_2^2+...+(c_L-c_{L-1})d_L^2$
$I_1 = \int_{c_1}^{c_2}2d_2xdx+\int_{c_2}^{c_3}2d_3\cdot 2xdx+...+\int_{c_{L_1}}^{c_L}2d_L(L-1)xdx=d_2(c_2^2-c_1^2)+d_3(c_3^2-c_2^2)+...+d_L(c_L^2-C_{L-1}^2)$
$I_2 = \frac{1}{3}(c_2^3-c_1^3)+\frac{4}{3}(c_3^3-c_1^3)+...+\frac{L^2}{3}(b^3-c_L^3)$
The answer is $I_1+I_2+I_3$ although in hindsight I'm not sure this is the way to go, but maybe it is.
A: This first part of this answer is for the original version of the question where $m = 2$.
Let $f(x) = \sum_{k=1}^L \max(x,a_k)$. Since each $\max(x,a_k)$ is a piecewise linear function, so does $f(x)$. As a result, $f^2(x)$ is a piecewise quadratic function. 
Let $s_1 \le s_2 \le \ldots \le s_\ell$ be the set of numbers among $a_1, a_2, \cdots a_L$ which fall inside $(a,b)$.
Let $s_0 = a$ and $s_{\ell+1} = b$. We have
$$\int_a^b f^2(x) dx = \left(\int_{s_0}^{s_1} + \int_{s_1}^{s_2} + \cdots + \int_{s_\ell}^{s_{\ell+1}}\right)f^2(x) dx
= \sum_{k=0}^\ell \int_{s_k}^{s_{k+1}} f^2(x)dx$$
Over each interval $(s_k,s_{k+1})$, $f^2(x)$ is a quadratic polynomial. The 
Simpson's rule for numerical integration becomes exact. As a result,
$$\int_a^b f^2(x) dx = \frac16\sum_{k=0}^\ell (s_{k+1}-s_k) \left[ f^2(s_k) + 4f^2\left(\frac{s_k+s_{k+1}}{2}\right) + f^2(s_{k+1})\right]$$
Update
For general $m$, we use the fact $f(x)$ is linear over each interval.
Let's say $f(x) = \alpha x + \beta$ on $(s_k,s_{k+1})$. If $f(s_{k+1}) \ne f(s_k)$, then $\alpha \ne 0$ and
$$\begin{align}
\int_{s_k}^{s_{k+1}} f^m(x) dx 
&= \int_{s_k}^{s_{k+1}} (\alpha x + \beta)^m dx
= \left[\frac{(\alpha x + \beta)^{m+1}}{(m+1)\alpha}\right]_{s_k}^{s_{k+1}}\\
&= \frac{s_{k+1}-s_k}{m+1}\left(
\frac{f^{m+1}(s_{k+1})-f^{m+1}(s_k)}{f(s_{k+1})-f(s_k)}
\right)
\end{align}
$$
If $f(s_k) = f(s_{k+1})$, the integral clearly equal to $(s_{k+1}-s_{k})f^m(s_{k+1})$. Combine these, we have
$$\int_a^b f^m(x) dx = \frac{1}{m+1} \sum_{k=0}^\ell (s_{k+1}-s_{k})\begin{cases}
\displaystyle\;\frac{f^{m+1}(s_{k+1}) - f^{m+1}(s_k)}{f(s_{k+1})-f(s_k)},& f(s_{k+1}) \ne f(s_k)\\
\\
(m+1)f^m(s_k), & f(s_{k+1}) = f(s_k)
\end{cases}$$
