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.

I am trying to plot the partial sums and the cesaro means of the function $\sqrt{|x|}$ and for $a_{n}$, I obtained the following code which contains FresnelS.

(-((Sqrt[2] FresnelS[Sqrt[2] Sqrt[n]])/n^(3/2)) - (Sqrt[2] FresnelS[Sqrt[2] Sqrt[Abs[n]]])/Abs[n]^(3/2) + (2 Sin[n \[Pi]])/n + (2 Sin[\[Pi] Abs[n]])/Abs[n])/(2 Sqrt[\[Pi]])

Now my question is is it possible to graph such function using Mathematica? I have tried many examples using trial and error and some of the my examples also contain BesselJ which can't be graph.

Hence I would like to know if it is true that if there is BesselJ and FresnelS in the code, then the graph cannot be drawn using Mathematica. Please correct me if I am wrong. I am graphing out its graph using this code:

f[x_] := Sqrt[Abs[Mod[x, 2 Pi, -Pi]]];
s[k_, x_] := ???
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]}}]
share|improve this question

1 Answer 1

up vote 4 down vote accepted

Coding Issue:

You can try to use DiscretePlot for the above expression out of the box in Mathematica!

DiscretePlot[
Evaluate@(-((Sqrt[2] FresnelS[Sqrt[2] Sqrt[n]])/
    n^(3/2)) - (Sqrt[2] FresnelS[Sqrt[2] Sqrt[Abs[n]]])/
  Abs[n]^(3/2) + (2 Sin[n \[Pi]])/n + (2 Sin[\[Pi] Abs[n]])/
  Abs[n])/(2 Sqrt[\[Pi]]), {n, 1, 150}]

enter image description here

Your code has minor typos! Before plotting always better to check what your functions are returning given an argument then you can spot the mistake in your code.

f[x_] := Sqrt[Abs[Mod[x, 2 Pi, -Pi]]];
s[k_, x_] :=Sum[(2 - 2 Cos[n \[Pi]] - n \[Pi] Sin[n \[Pi]])/(n^2 \[Pi]) Cos[
n x], {n, 1, k}]
partialsums[x_] = First@Table[N@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},
PlotStyle -> {{Blue}, {Dashed, Thickness[0.006]}, {Red,Thickness[0.006]}}]

enter image description here

Actual Answer:

Definition: Let ${a_n}_{n=0}^\infty$ be a sequence of real (or possibly complex numbers). The Cesaro mean of the sequence $\{a_n\}$ is the sequence $\{b_n\}_{n=0}^\infty$ with $$\begin{equation} b_n = \frac{1}{n+1} \sum_{i=0}^{n} a_i. \end{equation}$$

Code: Define the partial sum and the cesaro mean to take only Integer argument!

f[x_] := N@Sqrt[Abs[Mod[x, 2 Pi, -Pi]]]; 
part[k_?IntegerQ] := Total[(N@f[#]) & /@ Range[0, k]];
cesaro[k_?IntegerQ] := part[k]/(k + 1);

Testing: Check functions only evaluate for Integer argument.

Evaluate@{f[k], part[k], cesaro[k]} /. k -> 2

{1.41421, 2.41421, 0.804738}

Now plotting what you want!

DiscretePlot[Evaluate@{f[k], cesaro[k]}, {k, 1, 50}, Frame -> True, 
PlotStyle -> {{Red, PointSize[Medium]}, {Blue, Dashed}},Joined -> {False, True}]

enter image description here

share|improve this answer
1  
I had modified my post above. I am not trying to graph this function but I am trying to graph this in another terms. Do look at my code above. –  Sandra Jan 15 '13 at 20:09
    
Oops! I see. I think I had a mistake in my post as I just copy and paste. The s[k_, x_] part is wrong. This is one of my tryout for the function Pi/2 - Abs[x] with its correspondence s[k_, x_] but for my actual Sqrt[Abs[Mod[x, 2 Pi, -Pi]]] I can't find its partial sums due to this Fresnel function. –  Sandra Jan 15 '13 at 20:22
    
So discreteplot is my only choice after all in order for me to graph these type of functions. I am trying to plot like the second diagram you had posted above but to no avail. Thanks Platomaniac. You had solve a lot of my queries with Mathematica. –  Sandra Jan 15 '13 at 21:07
    
@Sandra you can use many other plotting functions too. But DiscretePlot can take your expression as it is. –  PlatoManiac Jan 15 '13 at 21:40

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.