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.
Answer
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] == 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.
Comments
Post a Comment