# Slow plot for integral involving FractionalPart and sine

I have defined this function:

f[x_]:=1/(1+Sin[FractionalPart[x]])


Then I tried to plot it using this code

Plot[Integrate[f[t],{t,0,x}],{x,0,2}]


It finally plot it, but it takes about 4-5 minutes to do it. There is a way to speed up similar plots, that involve commands as FractionalPart?

EDIT: I observed that changing Integrate by NIntegrate the plot speed up a lot, but Im not sure how accurate is the numerical integration to trust in the result of the plot.

Anyway I will like to know if there are other approaches to this problem using the symbolic integration. Thank you.

• Since you'e plotting over a (necessarily) limited domain: Assuming[0 < x < 2, Integrate[PiecewiseExpand[1/(1 + Sin[FractionalPart[t]]), 0 < t < 2] // Evaluate, {t, 0, x}]] – J. M. will be back soon May 11 '17 at 16:59
• Could avoid repeated symbolic integrals: f[x_?NumberQ] := 1/(1 + Sin[FractionalPart[x]]) Plot[NIntegrate[f[t], {t, 0, x}], {x, 0, 2}] One could further improve by keeping track of prior quadrature results and only adding increments. – Daniel Lichtblau May 11 '17 at 17:01
• As a comment, looking at the function: Plot[1/(1 + Sin[FractionalPart[x]]), {x, 0, 10.7}] The integration will be Assuming[x > 0, IntegerPart[x]*Integrate[1/(1 + Sin[x]), {t, 0, 1}] + Integrate[f[t], {t, 0, FractionalPart[x]}]] which is somthig like manual using PiecewiseExpand – David Baghdasaryan May 11 '17 at 17:12

You could use DSolve to calculate the symbolic integral over a finite interval.

ClearAll[f];
f[x_] := 1/(1 + Sin[FractionalPart[x]])

F = y /. First@DSolve[{y'[x] == f[x], y == 0}, y, {x, 0, 2}]

Plot[F[x], {x, 0, 2}] It's reasonably fast: Addendum: There is a reason I thought to try this. Events were added to DSolve a couple of versions ago, and these are used in discontinuity processing. What I imagine happens is this. When you've got an integrand with a standard discontinuous function, DSolve will split up the intervals and feed simple, continuous integrands to Integrate[]. It then adds up the results and pieces them together. At least that's how it seems when this trick works. I'm not familiar with the internal implementation.

• this works, thank you. – Masacroso May 11 '17 at 17:37
• one last question, why you used the command /. in the definition of F? – Masacroso May 11 '17 at 17:38
• @Masacroso You're welcome, but why did you change the function after I answered? -- DSolve returns a rule y -> func, but we need func to do the graph. You could use the newer F = DSolveValue[..] instead, but in my own work, I usually want the rule until the problems are completely worked out. – Michael E2 May 11 '17 at 17:41