4
$\begingroup$

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:

Integrate Piecewise

Any suggestions?

$\endgroup$
  • $\begingroup$ Your expected output for the second case seems to be wrong. You should get 1/2 for t=1 $\endgroup$ – george2079 Dec 23 '16 at 20:58
  • $\begingroup$ (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. $\endgroup$ – Michael E2 Dec 25 '16 at 14:57
  • $\begingroup$ @Michael E2 I need to Integral of all functions in pieceswise, separately, without consider distance. $\endgroup$ – user45459 Dec 25 '16 at 16:03
  • $\begingroup$ 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}]. $\endgroup$ – Michael E2 Dec 25 '16 at 16:12
  • $\begingroup$ @Michael E2 Many many thanks. Your comment is my answer. If possible for you change comment to answer, and reply about : {1, All, 1}. $\endgroup$ – user45459 Dec 25 '16 at 16:17
4
$\begingroup$

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}]]

Mathematica graphics

| improve this answer | |
$\endgroup$
  • $\begingroup$ I edited my question. Please review if possible. $\endgroup$ – user45459 Dec 23 '16 at 20:51
  • 2
    $\begingroup$ @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].) $\endgroup$ – Michael E2 Dec 25 '16 at 15:00
4
$\begingroup$

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

| improve this answer | |
$\endgroup$
  • $\begingroup$ I edited my question. Please review if possible. $\endgroup$ – user45459 Dec 23 '16 at 20:51
  • 1
    $\begingroup$ even Assuming[Element[t, Reals], ..] works (including the 0 for t<0 part) $\endgroup$ – george2079 Dec 23 '16 at 20:53
2
$\begingroup$

There's also

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

enter image description here

Advantage: no Assumptions/Assuming.

| improve this answer | |
$\endgroup$

Your Answer

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

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