# Getting error message when integrating a simple piecewise function

I reviewed the following questions: question 1 and question 2, but I need to the following integral of a piecewise function:

A[1][t_] = Piecewise[{{1 - 2*t, 0 <= t <= 1/2}}, 0]
Integrate[A[1][x], {x, 0, t}]


I want the following output

Piecewise[{{t - t^2, 0 <= t <= 1/2}}, 0]


but I get the error

Integrate::pwrl: Unable to prove that integration limits {0,t} are real. Adding assumptions may help.

Also, for

A2[t_] = Piecewise[{{2*t, 0 <= t <= 1/2}, {2 - 2*t, 1/2 <= t <= 1}}, 0]


I need the following output:

Any suggestions?

• Your expected output for the second case seems to be wrong. You should get 1/2 for t=1 – george2079 Dec 23 '16 at 20:58
• (1) You shouldn't expand questions after people have answered, unless you weren't clear enough to begin with. (2) Your second question doesn't make sense. Guessing you might mean you want the integral of A2, then the needed output is wrong. – Michael E2 Dec 25 '16 at 14:57
• @Michael E2 I need to Integral of all functions in pieceswise, separately, without consider distance. – user45459 Dec 25 '16 at 16:03
• But the way the integral is defined in calculus, and in Mathematica, the result should be continuous, which your desired output is not. This will output what you want: MapAt[Integrate[#, t] &, A2[t], {1, All, 1}]. – Michael E2 Dec 25 '16 at 16:12
• @Michael E2 Many many thanks. Your comment is my answer. If possible for you change comment to answer, and reply about : {1, All, 1}. – user45459 Dec 25 '16 at 16:17

This works for me:

ClearAll[x, t]
A0[t_] := Piecewise[{ {1 - 2*t, 0 <= t <= 1/2}}];
Assuming[t > 0, Integrate[A0[x], {x, 0, t}]]


• I edited my question. Please review if possible. – user45459 Dec 23 '16 at 20:51
• @user45459 I would add that Nasser is only following the advice in the error message. (Literally, it was suggesting Integrate[A[1][x], {x, 0, t}, Assumptions -> t \[Element] Reals], or rather Integrate[A[1][x], {x, 0, t}, Assumptions -> {0, t} \[Element] Reals].) – Michael E2 Dec 25 '16 at 15:00

Ok it may be strange to put an assumption on t but this

A[1][t_] = Piecewise[{{1 - 2*t, 0 <= t <= 1/2}}, 0]
Assuming[0 <= t <= 1, Integrate[A[1][x], {x, 0, t}]]


works

• I edited my question. Please review if possible. – user45459 Dec 23 '16 at 20:51
• even Assuming[Element[t, Reals], ..] works (including the 0 for t<0 part) – george2079 Dec 23 '16 at 20:53

There's also

A[1][t_] = Piecewise[{{1 - 2*t, 0 <= t <= 1/2}}, 0];
FullSimplify @ Normal @ Integrate[SimplifyPWToUnitStep @ A[1][x], {x, 0, t}]


Advantage: no Assumptions/Assuming`.