I have a simple function:

func =x Sin[π x]^2

This creates a curve that oscillates between 0 and values that increase linearly with x.

I want to create a continuous sum of func, so that incremental increases in x add to the running total. The result would be a continuously rising curve, with periods of rapid growth interspersed with periods of something closer to a plateau, based on the frequency of the Sin function.

How do I do this?


closed as off-topic by AccidentalFourierTransform, Johu, corey979, eyorble, Henrik Schumacher Sep 25 '18 at 7:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – corey979, eyorble, Henrik Schumacher
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ f=Integrate[x Sin[Pi x]^2,x] ; Plot[f,{x,0,4Pi}] $\endgroup$ – Bill Sep 24 '18 at 0:18
  • 1
    $\begingroup$ How does a "continous summation" differ from an integral? $\endgroup$ – Αλέξανδρος Ζεγγ Sep 24 '18 at 1:04
  • $\begingroup$ I went to sleep last night realising what a dumb question it was! Many thanks for the answers. $\endgroup$ – Richard Burke-Ward Sep 24 '18 at 7:58

The "continuous sum" of a function is it's integral so

f[x_] := x Sin[Pi x]^2
sumf = Integrate[f[x], x];
Plot[{f[x], sumf}, {x, 0, 2 Pi}]

enter image description here


You can also use Accumulate

f[x_] := x Sin[Pi x]^2
n = 10000;
sumf = Accumulate@(2 Pi/n f@Subdivide[0., 2 Pi, n]);
Show[ListLinePlot[sumf, DataRange -> {0, 2 Pi}, 
  PlotStyle -> ColorData[97, 2], PlotRange -> All], 
 Plot[f[x], {x, 0, 2 Pi}]]

enter image description here


Not the answer you're looking for? Browse other questions tagged or ask your own question.