Integral of a piecewise given function

integrationpiecewise-continuity

In the course of work, I deduced such an expression.

$$
p(t)=\int\limits _{-\infty}^{\infty}\begin{cases}
1/x_{max}, & 0\leq t<x\\
0, & other
\end{cases}\cdot dx,
$$

where $x \in [0,x_{max}]$ ($x_{max} = 10$ for example),

$t$ – is variable.

I have built a graph that is calculated numerically using python.

import numpy as np
import matplotlib.pyplot as plt

x_max = 10
t = np.linspace(-x_max * 0.1, x_max * 1.1, 1000)

num_point = 1000
pre_p = np.zeros((num_point, t.size))
x = np.linspace(0, x_max, num_point)

for i, this_x in enumerate(x):
    pre_p[i] = np.where((0 <= t) & (t < this_x),  1/x_max, 0)

p = np.trapz(pre_p, x=x, axis=0)


plt.plot(t, p)

enter image description here

I intuitively figured out how this function should look in symbolic form.

$$
p(t)=\begin{cases}
1-\frac{t}{x_{max}}, & 0\leq t<x_{max}\\
0, & other
\end{cases}
$$

But how can the integral be taken symbolically according to the rules of mathematics? The thing is, my function is piecewise. And the variable by which I integrate is right in the condition.
It would be great to have links to literature or an article, thanks.

Best Answer

Define $$f(t,x) = \begin{cases} \frac 1{x_{\max}},& t\in[0,x]\\0,& t\notin [0,x]\end{cases}$$

Then $$p(t) = \int_0^{x_\max} f(t, x)\,dx$$ Where the limits are from $0$ to $x_\max$, not $-\infty$ to $\infty$, because you said yourself that $x\in [0, x_\max]$. Note that in your definition of $p(t), x$ is a dummy variable, not an actual part of the definition. Its only purpose is to make the notation work. You could switch to a different variable (other that $t$ and $x_\max$, which already have roles) without changing the meaning at all. So in saying $x\in [0, x_\max]$, you are just admitting that you goofed up the limits of the integration.

Now break it out into two cases:

  • $t < 0$ or $t > x_\max$. Then $t\notin [0,x]$ for all $x$ in the limits, so $f(t,x) = 0$ and $\int_0^{x_\max} 0\,dx = 0$
  • $t \in [0, x_\max]$. Then $$\begin{align}p(t) &= \int_0^{x_\max} f(t, x)\,dx \\&= \int_0^t f(t, x)\,dx + \int_t^{x_\max} f(t, x)\,dx\\&=\int_0^t 0\,dx + \int_t^{x_\max} \dfrac 1{x_\max}\,dx\\&= 0 + \dfrac 1{x_\max}(x_\max -t)\\&=1 - \dfrac t{x_\max}\end{align}$$

Putting it together: $$p(t) = \begin{cases}0,& t < 0\\1 - \dfrac t{x_\max}, & 0 \le t \le x_\max\\0,& x_\max < t\end{cases}$$

Related Question