I'm trying to integrate a piecewise function symbolically and I'm ending up with discontinuities which is surprising since the help mentions that constants are determined to ensure continuity.

If I replace my constants BEFORE doing the integration, the result IS continuous. Other posts on SO mentioned that the continuity cannot be done in the case of multiple variables, but I have tried to make it clear that only my "t" symbol is a variable.

The variable replaceConstantsBeforeIntegration can be set to True or False to determine whether the constants are replaced before or after integration.

Any ideas? I'm a Mathematica newbie so feel free to give me any suggestions for improvement.

replaceConstantsBeforeIntegration = False;
$Assumptions = duration1 > 0 & duration2 > 0 && t > 0;
SetAttributes[{duration1, duration2}, Constant];
jer1 = Sin[(Pi*t)/duration1] ;
jer2 = 1;
constants = {duration1 -> 6, duration2 -> 5};

jerks = {jer1, jer2};
boundaries = {t < duration1, t < duration1 + duration2};

jer = Piecewise[Transpose[{jerks, boundaries}]] /. 
   If[replaceConstantsBeforeIntegration, constants, {}];
acc = Integrate[jer, t, Assumptions -> {t \[Element] Reals}];

domain = {t, 0, duration1 + duration2} /. constants;
Plot[jer /. constants, domain, PlotRange -> Full]
Plot[acc /. constants, domain, PlotRange -> Full]

You want the definite integral, not the antiderivative:

acc = Integrate[jer /. t -> $t, {$t, 0, t}, 
   Assumptions -> {t \[Element] Reals}];

Plot[acc /. constants, domain, PlotRange -> Full]

enter image description here


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.