2
$\begingroup$
f[x_] := Piecewise[{{1, -0.5 <= x <= 0.5}}, 0];
ProbabilityDistribution[
 Integrate[f[a], {a, x - 0.5, x + 0.5}], {x, -2, 2}]

output: "Unable to prove that integration limits {-(1/2)+x,1/2+x} are real. \ Adding assumptions may help. !(*ButtonBox[\">>\", Appearance->{Automatic, None}, BaseStyle->\"Link\", ButtonData:>\"paclet:ref/Integrate\", ButtonNote->\"Integrate::pwrl\"])"

$\endgroup$

1 Answer 1

4
$\begingroup$

Assumptions is an option to Integrate. The message is telling you to add the assumption that x is real (by default, variables are usually treated as complex).

f[x_] := Piecewise[{{1, -1/2 <= x <= 1/2}}, 0];
ProbabilityDistribution[
 Integrate[f[a], {a, x - 1/2, x + 1/2}, 
  Assumptions -> x ∈ Reals], {x, -2, 2}]

Mathematica graphics

For this simple example one could also use

ProbabilityDistribution[
 Integrate[UnitBox[a], {a, x - 1/2, x + 1/2}, 
  Assumptions -> x ∈ Reals], {x, -2, 2}]

or

TriangularDistribution[{-1, 1}]

(in case that helps).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.