1
$\begingroup$

I am trying to plot the partial sums and the Cesàro 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 π])/n + (2 Sin[π Abs[n]])/Abs[n])/(2 Sqrt[π])

Now my question is, is it possible to graph such a 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 graphed.

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]}}]
$\endgroup$

1 Answer 1

5
$\begingroup$

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 π])/n + (2 Sin[π Abs[n]])/
  Abs[n])/(2 Sqrt[π]), {n, 1, 150}]

DiscretePlot result

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 π, -π]]];
s[k_, x_] := Sum[(2 - 2 Cos[n π] - n π Sin[n π])/(n^2 π) Cos[n x], {n, 1, k}]
partialsums[x_] = First @ Table[N @ s[n, x], {n, {4}}];
c[n_, x_] := Sum[s[m, x], {m, 0, n - 1}]/n;
Plot[Evaluate[{f[x], partialsums[x], c[4, x]}], {x, -π, π},
PlotStyle -> {{Blue}, {Dashed, Thickness[0.006]}, {Red,Thickness[0.006]}}]

function with partial sums and Cesàro means

Actual Answer:

Definition: Let ${a_n}_{n=0}^\infty$ be a sequence of real (or possibly complex numbers). The Cesàro 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 Cesàro mean to take only Integer argument!

f[x_] := N @ Sqrt[Abs[Mod[x, 2 π, -π]]]; 
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}]

DiscretePlot of Cesàro means

$\endgroup$
4
  • 1
    $\begingroup$ 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. $\endgroup$
    – Sandra
    Commented Jan 15, 2013 at 20:09
  • $\begingroup$ 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. $\endgroup$
    – Sandra
    Commented Jan 15, 2013 at 20:22
  • $\begingroup$ 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. $\endgroup$
    – Sandra
    Commented Jan 15, 2013 at 21:07
  • $\begingroup$ @Sandra you can use many other plotting functions too. But DiscretePlot can take your expression as it is. $\endgroup$ Commented Jan 15, 2013 at 21:40

Your Answer

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

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