3
$\begingroup$

The function I would like to plot is defined as $\sum\limits_{p\leq x}\log p.$ The following gives me I think a plot of the points of interest, but the function is defined for all $x > 0$ and so it's basically a step function between primes. Is there a way to augment the following to include the "steps?"

a8 = Table[Sum[Log[Prime[i]], {i, 1, j}], {j, 1, 10}];

a7 = Table[Prime[i], {i, 1, 10}];

a9 = Table[{a7[[i]], a8[[i]]}, {i, 1, 10}];

ListPlot[a9]

Thanks for any suggestions.

$\endgroup$
5
$\begingroup$

Here's Eric Weisstein's implementation from MathWorld:

Primorial[0] := 1;
Primorial[1] := 2;
Primorial[n_] := Primorial[n] = Prime[n] Primorial[n - 1];
ChebyshevTheta[n_] := Log[Primorial[PrimePi[n]]]

Plot[ChebyshevTheta[x], {x, 0, 100}]

enter image description here

Many MathWorld pages have attached notebooks linked near the top of the page. That's where this came from.

$\endgroup$
  • $\begingroup$ Thank you I had seen this but did not realize there was code to be found. $\endgroup$ – daniel Dec 12 '12 at 21:48
  • $\begingroup$ @daniel Yes, the code is the best part of the answer! $\endgroup$ – Mark McClure Dec 12 '12 at 21:49
  • $\begingroup$ You might need some more PlotPoints in there to get rid of that wee glitch in the middle. $\endgroup$ – wxffles Dec 13 '12 at 0:52
  • $\begingroup$ It might be more prudent to just add logarithms directly instead of multiplying a bunch of primes before taking the logarithm. $\endgroup$ – J. M. will be back soon Apr 19 '13 at 16:39
2
$\begingroup$

Trying to stay as close to your definitions as possible, one may actually want to avoid Plot because it will have trouble when the number of discontinuities is too large to be properly resolved for a given choice of PlotPoints. Instead, as you already started out doing, one can use a list plot. But to get lines, you should use ListLinePlot and define the corners of the step functions:

n = 50;

a8 = Table[Sum[Log[Prime[i]], {i, 1, j}], {j, 1, n}];

a7 = Table[Prime[i], {i, 1, 50}];

a9 = Transpose[{a7, a8}];

a10 = Transpose[{Rest[a7], Most[a8]}];

ListLinePlot[Riffle[a9, a10]]

steps

This guarantees all steps to be nicely rectangular. Here, the number of jumps is given by n = 50.

What I did is to simplify your definition of a9 without changing it, and then adding a list a10 where all the x-values are shifted to the right in order to define the right side of each horizontal segment. These two lists a9 and a10 are then combined with Riffle so that elements from each list alternate, giving the desired line.

You can increase n without having to worry about the PlotPoints option in Plot.

$\endgroup$
  • $\begingroup$ Thank you, I hadn't seen "Riffle" before. This is a nice idea and I did notice for large n a lot of error messages before the Weisstein implementation actually displayed the graph. +1 $\endgroup$ – daniel Dec 13 '12 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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