# Integral of a piecewise given function

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

$$p(t)=\int\limits _{-\infty}^{\infty}\begin{cases} 1/x_{max}, & 0\leq t 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)


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

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

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.

• Your notation of the map being integrated in the first integral is rather confusing. It will help if: (1) you define what $x_{max}, t_{max}$ are and (2) write the function $f(x,t)$ being integrated outside of the integral. Is it a function of two variables $t,x$? Apr 20 '21 at 12:47
• Seeing as the graph has no additional area when x=0, it can be done that $Area=\int_0^{10}1-\frac{x}{10} dx$ after finding the line with the points (0,1) and (10,0) as the endpoints to get Area=$(x-\frac{x^2}{20})|_0^{10}$=$10-\frac{10^2}{20}-0$=5 Apr 20 '21 at 12:48
• corrected the question. I am interested in taking the integral. Apr 20 '21 at 13:00

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.
• $$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}$$