<s>[INST] Calculating definite integral with absolute value I need to evaluate, with $a,c>0$, the integral:
$$\int_{-a}^a\left(1-\frac{|x-y|}c\right)\,dy$$
This is what i tried
if $x>y:$
$$\int_{-a}^a\left(1+\frac{y-x}c\right)\,dy=2 a-\frac{2 a x}{c}$$
if $x<y:$
$$\int_{-a}^a\left(1+\frac{x-y}c\right)\,dy=2 a+\frac{2 a x}{c}$$
is this right? Can I combine the two?
 [/INST] For $x \in (-a,a) $
$$I \equiv \int_{-a}^a\left(1-\frac{|x-y|}c\right)\,dy \\ = \frac 1c\int_{-a}^x\left( c-x+y \right)\,dy
\\ + \frac 1c\int_{x}^a\left( c+x-y \right)\,dy
\\ = \frac 1c  \left[  (c-x)(x+a)+(c+x)(a-x) \right]
\\ =  \frac 1c  (-2x^2+2ac) =2a-2\frac{x^2}{c}  $$
for $x<-a$
$$I = 2a+2\frac{ax}c  $$
for $x>a$
$$I = 2a-2\frac{ax}c  $$
</s>