Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

For a given function:

Plot[Sqrt[Abs[x]], {x, -Pi, Pi}]

I have the code to draw the function (with its Abs remove), partial sums and cesaro means as:

f[x_] := Sqrt[x]
s[k_, x_] := \frac{2\sqrt{\pi}}{3}+(-Sqrt[2] FresnelS[Sqrt[2] Sqrt[n]] + 2 Sqrt[n] Sin[n \[Pi]])/(n^(3/2) Sqrt[\[Pi]]) 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, -Pi, Pi},
PlotLegends -> {"f(x)=x", "Fourier, 4 terms", "Cesaro, 4 terms"}, 
PlotStyle -> {{Blue}, {Dashed, Thickness[0.006]}, {Red, Thickness[0.006]}}]

This code fails on my computer and hence I resolve to manual computation.

Updates: It turn out that I can easily solve this issue by removing the k with any number rather than letting it to be indefinite. Although I am not certain the graph is right for k=4 as both graphs(Partial and Cesaro) coincides with each other.

share|improve this question
    
You can use Show to combine different plots. –  b.gatessucks Jan 16 '13 at 17:07
1  
All the integrals you list for $n=1,2,\ldots,5$ are zero: you seem to be displaying some kind of floating point error. They are not relevant to the $a_n$ anyway. So what really is your question? –  whuber Jan 16 '13 at 17:24
    
Thank you for changing those erroneous values--although the integrands are now incorrect, because they omit most of the function. (However, I do not understand why you need "manual computation" when you have already exhibited a valid Mathematica formula for computing the $a_n$.) I also do not understand what you mean by a "continuous" graph to "contain" these discrete values. An example or a sketch might help convey your intentions. –  whuber Jan 16 '13 at 17:43
    
@whuber: I had re-edited the post. Do let me know if it is not clear and I will try to improve it again. –  Sandra Jan 16 '13 at 17:56
    
I'm still lost: $a_n$ defines a sequence $a_0, a_1, \ldots, a_n, \ldots$. It is inherently discrete. What "smooth curve" are you hoping to draw with this sequence? –  whuber Jan 16 '13 at 18:22

1 Answer 1

up vote 2 down vote accepted

Maybe

plt = Plot[f[k], {k, 0, 50}, Frame -> True, PlotStyle -> Red,ImageSize -> 300];
dplt = DiscretePlot[cesaro[k], {k, 0, 50}, Frame -> True, PlotRange -> PlotRange[plt],
PlotStyle -> Directive[{Blue, Dashed}], Joined -> True, ImageSize -> 300]; 
Row[{plt, dplt, Show[plt, dplt]}]

enter image description here

Update: or, perhaps, this:?

 dplt2 = DiscretePlot[cesaro[k], {k, 0, 50}, Frame -> True, Filling -> None, 
 PlotRange -> PlotRange[plt], PlotStyle -> Blue, Joined -> True, ImageSize -> 300];
 Row[{plt, dplt2, Show[plt, dplt2]}]

enter image description here

or, using Interpolation on cesaro[k] and

 intFCsr = Interpolation[Table[{k, cesaro[k]}, {k, 0, 50}]];
 Plot[{f[k], intFCsr[k]}, {k, 0, 50}, Frame -> True,PlotStyle -> {Red, Blue}]

enter image description here

Update 2:

 intFCsr = Interpolation[Table[{k, cesaro[k]}, {k, 0, 50}]];
 intFPrtlSms = Interpolation[Table[{k, part[k]}, {k, 0, 50}]];
 Plot[{f[k], intFCsr[k], intFPrtlSms[k]/15}, {k, 0, 50},  ImagePadding -> 45,
 Frame -> True, PlotStyle -> {Red, Blue, Black}, ImageSize -> 500,
 FrameLabel -> {{Style["f, cesaro", 12], Style["partial sum", 12]},
   {Style["k", 12], Style["plot label", 14]}},
 FrameTicks -> {{Join[{#, #, {.01, 0}} & /@ Range[0, 4.],
   {#, " ", {.0075, 0}} & /@ Range[0.2, 4., .2]],
  Join[{#, 15 #, {.01, 0}} & /@ Range[0, 4.],
    {#, " ", {.0075, 0}} & /@ Range[0.2, 4., .2]]}, {Automatic, Automatic}}]

enter image description here

share|improve this answer
    
Oh, this edited version looks good! Now that you had inserted the cesaro means graph, do you think it is possible to combine the partial sums graph into it so that there are altogether three graphs? The function as shown in the diagram is in red while the cesaro is in blue. Perhaps we can have the partial sums line as black if possible. I look forward to your help kguler. Amazing updates indeed. –  Sandra Jan 17 '13 at 2:12
    
@Sandra, does this give what you need: intFPrtlSms = Interpolation[Table[{k, part[k]}, {k, 0, 50}]]; Plot[{f[k], intFCsr[k], intFPrtlSms[k]}, {k, 0, 50}, Frame -> True, PlotStyle -> {Red, Blue, Black}]? –  kguler Jan 17 '13 at 2:23
    
Amazing! May I know why are the labels "f,cesaro" on the left of y axis while "partial sum" on the right hand side of y-axis? When I use Plot function, I plot all diagrams based on x-axis. I am not sure if the two graph of cesaro and the partial is correct but I am certain the function graph is correct. –  Sandra Jan 17 '13 at 4:50
    
@Sandra, if you use f and the interpolated versions of your cesaro and part functions in the same plot (Plot[{f[k], intFCsr[k], intFPrtlSms[k]}, {k, 0, 50}, ImagePadding -> 45, Frame -> True, PlotStyle -> {Red, Blue, Black}, ImageSize -> 500]) gives a graph in which the details of f and cesaro are not visible because their vertical scale is much smaller then that of part - hence two different vertical scales. –  kguler Jan 17 '13 at 8:48
    
thank you so much for these changes and explanation. I had voted this as the answer and thank you! –  Sandra Jan 17 '13 at 18:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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