Alternatives to piecewise
You can use the functions Simplify`PWToUnitStep
and Simplify`SimplifyUnitStep
to convert a Piecewise
function to one using UnitStep
:
s[t_] := Piecewise[{{1, t < 300.}, {0, 300. <= t < 1500.}, {1, t <= 3600}}];
s2[t_] := Simplify`SimplifyUnitStep[Simplify`PWToUnitStep[s@t]];
s2[t]
1 - UnitStep[-300. + t] + UnitStep[3600 - t, -1500. + t]
To use HeavisideTheta
instead of UnitStep
:
s2[t] /. UnitStep -> HeavisideTheta
1 - HeavisideTheta[-300. + t] + HeavisideTheta[3600 - t, -1500. + t]
Row[Plot[#, {t, 0., 4000.}, PlotStyle -> Thick, ImageSize -> 300] & /@ {s[t], s2[t]}]
Two alternatives (depending on application) would be UnitStep
and HeavisideTheta
. For example,
sU[t_] := UnitStep[300 - t] + UnitStep[t - 1500, 3600 - t]
sH[t_] := HeavisideTheta[300 - t] + HeavisideTheta[t - 1500, 3600 - t]
For differential equations, I would use HeavisideTheta
.