sunilsn
(Sunil Nandihalli)
May 30, 2018, 5:43am
1
Hi,
I am unable to obtain piecewise representations of integrals of piecewise functions beyond the first integral. I am pasting the code used below.
For better readability, I have also attached the pdf of the notebook.
I would appreciate any help in resolving this issue.
Thanks and regards,
Sunil
f[intervals_]:= Function[{x}, Plus@@Map[Function[{a,b,c},UnitStep[x-a]UnitStep[b-x]c]@@#&,intervals]]
g:=f[{{0,1,1},{2,3,-1},{4,5,-1}}]
assum:= 0<=t<=10 && t\[Element]Rationals && p\[Element]Rationals && q\[Element]Rationals && r\[Element]Rationals
ig[t_] := PiecewiseExpand[FullSimplify[Integrate[g[p],{p,0,t}],Assumptions->assum]]
iig[t_]:= PiecewiseExpand[FullSimplify[Integrate[ig[q],{q,0,t}],Assumptions-> assum]]
iiig[t_]:= PiecewiseExpand[FullSimplify[Integrate[iig[r],{r,0,t}],Assumptions->assum]]
Plot[{g[t],ig[t],iig[t],iiig[t]},{t,0,10}]
This way it seems to work:
f[intervals_] :=
Function[{x},
Evaluate[
Plus @@ Map[
Function[{a, b, c}, UnitStep[x - a] UnitStep[b - x] c] @@ # &,
intervals]]];
g = f[{{0, 1, 1}, {2, 3, -1}, {4, 5, -1}}];
Clear[t];
ig[t_] = PiecewiseExpand@
Integrate[g[p], {p, 0, t}, Assumptions -> Element[t, Reals]]
iig[t_] = Integrate[ig[q], {q, 0, t}, Assumptions -> Element[t, Reals]]
iiig[t_] =
Integrate[iig[q], {q, 0, t}, Assumptions -> Element[t, Reals]]
Plot[{g[t], ig[t], iig[t], iiig[t]}, {t, 0, 10}]
sunilsn
(Sunil Nandihalli)
May 30, 2018, 5:24pm
3
Hi Gianluca,
Thanks a lot for the reply.
Can you explain why the last integral is still not piecewise-expanded?
f[intervals_] :=
Function[{x},
Evaluate[
Plus @@ Map[
Function[{a, b, c}, UnitStep[x - a] UnitStep[b - x] c] @@ # &,
intervals]]];
g = f[{{0, 1, 1}, {2, 3, -1}, {4, 5, -1}}];
Clear[t];
ig[t_] = PiecewiseExpand@
Integrate[g[p], {p, 0, t}, Assumptions -> Element[t, Reals]]
Clear[t];
iig[t_] =
PiecewiseExpand @
Integrate[ig[q], {q, 0, t}, Assumptions -> Element[t, Reals]]
Clear[t];
iiig[t_] =
PiecewiseExpand @
Integrate[iig[q], {q, 0, t}, Assumptions -> Element[t, Reals]]
Clear[t];
Plot[{g[t], ig[t], iig[t], iiig[t]}, {t, 0, 10}]
It is expanded for me (version 11.3):
In[7]:= iiig[t] // InputForm
Out[7]//InputForm=
Piecewise[{{t^3/6, Inequality[0, Less, t, LessEqual, 1] || t < 0},
{-3 + 2*t, Inequality[3, Less, t, LessEqual, 4]}, {(-79 + 39*t - 3*t^2)/6, t > 5},
{(1 - 3*t + 3*t^2)/6, Inequality[1, Less, t, LessEqual, 2]},
{(9 - 15*t + 9*t^2 - t^3)/6, Inequality[2, Less, t, LessEqual, 3]},
{(46 - 36*t + 12*t^2 - t^3)/6, Inequality[4, Less, t, LessEqual, 5]}}, 0]
sunilsn
(Sunil Nandihalli)
June 1, 2018, 10:42am
5
Hi Gianiuca,
Sorry, when I tried again it worked. I must have missed something the previous time. Thanks for your help.