1
$\begingroup$

I am calculating the integral of two indicator functions with Mathematica. I'm having difficulty in imposing assumptions. What I have done so far:

To define an indicator function:

indicator[c_,d_][x_]:= Piecewise[{{1,c<=x <= d},{0, True}}];

Then the integral is:

Integrate[indicator[-1,1][x-y]*indicator[-n,n][y], {y,-Infinity, Infinity},Assumptions->{Element[n,Integers]}]

Now what I expected, was that it gives me the length of intersection between the two segments $[-n,n]$ and $[x-1,x+1]$, but it lists a set of cases for different values of n and x, but it is still assuming n is real, because it considers cases such as $0<n<1$. Any suggestions?

$\endgroup$
  • $\begingroup$ You know that Boole[] is built-in, no? $\endgroup$ – J. M.'s technical difficulties Nov 2 '15 at 15:10
  • $\begingroup$ @J.M. no :( but do you think the issue stems from my definition of "indicator" above? $\endgroup$ – user21766 Nov 2 '15 at 15:15
  • $\begingroup$ Use UnitBox or HeavisidePi, properly scaled. $\endgroup$ – David G. Stork Nov 2 '15 at 18:11
2
$\begingroup$
FullSimplify@Assuming[n > 0, 
 Integrate[
  UnitBox[2 (x - y)] UnitBox[n y], 
  {y, -\[Infinity], +\[Infinity]}]]

$\begin{cases} \frac{1}{2} & (n>0\land 4 n x+2>n\land 4 n x+n\leq 2)\lor (n=2\land x=0) \\ \frac{1}{n} & n>2\land 4 n x+n\geq 2\land 4 n x+2\leq n \\ \frac{1}{2}-x & n=2\land 0<x<\frac{1}{2} \\ x+\frac{1}{2} & n=2\land -\frac{1}{2}<x<0 \\ \frac{-4 n x+n+2}{4 n} & 4 n x<n+2\land ((n>2\land 4 n x+2>n)\lor (4 n x+n>2\land n<2)) \\ \frac{1}{2 n}+x+\frac{1}{4} & 4 n x+n+2>0\land ((n>2\land 4 n x+n<2)\lor (n<2\land 4 n x+2\leq n)) \end{cases}$

| improve this answer | |
$\endgroup$
  • $\begingroup$ Clearly, then: UnitBox[2 n y]. I'll let you figure out the cases with non-zero centers, etc. $\endgroup$ – David G. Stork Nov 2 '15 at 22:12
  • $\begingroup$ Try PiecewiseExpand[UnitBox[2ny]] ... This is -1/(4n)<=y<=1/(4n) $\endgroup$ – user21766 Nov 3 '15 at 1:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy