I have the function as shown in the first line of the code and its partial sum in the second line of the code below.

f[x_] := Abs[x];
s[k_, x_] := (Pi/2) + Sum[((-1)^(n) - 1) 2/(Pi n^(2)) Cos[n x], {n, 1, k}] 

Then I have the Cesàro means of the function:

$$F_{n}(f)=\frac{1}{n} \sum^{n-1}_{m=0} S_{m}(f)$$

Originally I plot just the function and its partial sum with the code

Plot[Evaluate[{f[x], partialsums}], {x, -0.5, 0.5}

Now if I want to add in the 4th term of the Cesàro means, may I know how can I do so? I made a few changes and there is always a + symbol appearing inline which I believe is due to some mistake in my program

The original plot without the Cesàro means is

f[x_] := Abs[x];
s[k_, x_] := Pi/2 + Sum[((-1)^(n) - 1) 2/(Pi n^(2)) Cos[n x], {n, 1, k}] 
partialsums = Table[s[n, x], {n, 4}];
Plot[Evaluate[{f[x], partialsums}], {x, -0.5, 0.5}]

When I introduce the Piecewise function to add the Cesàro means to my graph, no drawings were generated. Please help.


1 Answer 1


First, we need to straighten out some of the notation. Whereas your partial sum function s depends only upon the index k and the variable x but not the function f, your list partialsums does not depend on x and your Cesaro partial-sum function, as you expressed it in $\text{LaTeX}$ form, includes an explicit dependence on f. Let's omit the f on the last and do include the x with partialsums. Then:

f[x_] := Abs[x]
s[k_, x_] := 
    Pi/2 + Sum[((-1)^(n) - 1) 2/(Pi n^(2)) Cos[n x], {n, 1, k}]
partialsums[x_] = Table[s[n, x], {n, 4}];

c[n_, x_] := (1/n) Sum[s[m, x], {m, 0, n - 1}]

Plot[Evaluate[{f[x], partialsums[x], c[4, x]}], {x, -0.5, 0.5}]

Mathematica graphics

  • $\begingroup$ you didn't define the cesaro means in the code. So Mathematica can't generate a graph for it. $\endgroup$
    – Sandra
    Jan 9, 2013 at 16:46
  • $\begingroup$ @Sandra: I fixed that omission. BTW, did you know you can directly embed LaTeX code in questions here, by enclosing within dollar signs? $\endgroup$
    – murray
    Jan 9, 2013 at 16:49
  • $\begingroup$ Thanks Murray. Oh I didn't know about that. In my post, I think VLC edit it for me. Now when I graph your code, I do receive the function line and the 4th term of the partial sum line but for the 4th term of the Cesaro means there are two lines generated. Can you have a check on what is wrong in the code? $\endgroup$
    – Sandra
    Jan 9, 2013 at 16:52
  • $\begingroup$ When I put in the legends, it seem not match up: PlotLegends -> {"f(x)=x", "Fourier, 4 terms", "Cesaro, 4 terms"}, PlotStyle -> {Blue, Dashed, Red}] $\endgroup$
    – Sandra
    Jan 9, 2013 at 17:07
  • $\begingroup$ @sandra Since Murray is using partialsums in the plot which is a list with 4 functions you get 6 plots in total. You don't see all of them because there are two twin function involved. The printed functions you get in the output are caused by a missing ; in the code, or a definition using = instead of a :=. $\endgroup$ Jan 9, 2013 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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