1
$\begingroup$

I have curve given by summing a small, finite series of Sinc functions, and I want to plot both the curve and its integral. In principle, it's easy:

test[x_] := Sinc[Pi*x]^2 + Sinc[Pi*(x - 3)]^2 + Sinc[Pi*(x - 6)]^2 + 
 Sinc[Pi*(x - 9)]^2 + Sinc[Pi*(x - 12)]^2 + Sinc[Pi*(x - 15)]^2;
sumtest = Integrate[test[x], x]; 
Plot[{test[x], sumtest}, {x, 0, 15}, PlotLegends -> "Expressions"]

...but in practice, it's not working. Since the Sinc functions are all squared, the curve is necessarily positive at all points for real x. Therefore, the integral is also always positive. But my plot looks like this:

<code>Sinc^2</code> in blue, integral in orange

Can someone tell me what I'm doing wrong - and how to do it right?

$\endgroup$
  • 1
    $\begingroup$ Integrate[test[x], x] will give you only one of many possible antiderivatives, and not necessarily the one you want. You need an extra condition that will impose your positivity requirement. $\endgroup$ – J. M. will be back soon Sep 24 '18 at 12:19
  • $\begingroup$ OK. How do I do that? $\endgroup$ – Richard Burke-Ward Sep 24 '18 at 12:21
  • $\begingroup$ You seem to be starting from $0$, so try subtracting the result of Limit[Integrate[test[x], x], x -> 0] to your integral. $\endgroup$ – J. M. will be back soon Sep 24 '18 at 12:23
  • $\begingroup$ Exactly what I needed. Thank you. Want to promote your response to 'answer' so I can tick it? $\endgroup$ – Richard Burke-Ward Sep 24 '18 at 12:27
  • $\begingroup$ If I may: if you understand what Limit[Integrate[test[x], x], x -> 0] was supposed to compute, I encourage you to try writing an answer to your own question. :) I can then refine it if needed and maybe even upvote it. $\endgroup$ – J. M. will be back soon Sep 24 '18 at 12:29
3
$\begingroup$

Thanks to the generous input of @J.M. is somewhat okay, here is the answer:

I got mixed between definite and indefinite integrals (or antiderivatives). As a result, I wrote a formula that gave the generalised integral (antiderivative) rather than the partial integral specifically between x=0 and the end-point of the plot at x=15. I didn't spot that I'd made this assumption - and MMA, faced with an infinite range of equally valid assumptions about what constant to add to the antiderivative, chose a different number.

Subtracting a Limit[] as x->0 corrects for this:

test[x_] := Sinc[Pi*x]^2 + Sinc[Pi*(x - 3)]^2 + Sinc[Pi*(x - 6)]^2 + 
 Sinc[Pi*(x - 9)]^2 + Sinc[Pi*(x - 12)]^2 + Sinc[Pi*(x - 15)]^2;
sumtest = Integrate[test[x], x]-Limit[Integrate[test[x], x], x -> 0]; 
Plot[{test[x], sumtest}, {x, 0, 15}, PlotLegends -> "Expressions"]

enter image description here

$\endgroup$
  • $\begingroup$ Very minor nit: Integrate[] happened to give one possible antiderivative among infinitely many choices. Or put differently: Integrate[] gave you an antiderivative, but not the one you wanted where $F(0)=0$. $\endgroup$ – J. M. will be back soon Sep 24 '18 at 13:02
  • $\begingroup$ Noted and changed. Thanks JM :-) $\endgroup$ – Richard Burke-Ward Sep 24 '18 at 13:17
  • 1
    $\begingroup$ Or use sumtest[x_] = Assuming[x > 0, Integrate[test[t], {t, 0, x}]] $\endgroup$ – Bob Hanlon Sep 25 '18 at 3:27

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.