MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Percentage of Primes

On Sep 22, 2012, at 2:47 AM, Jared E <eggers.jared at> wrote:

> I'm brand new to Mathematica, so there's only so much I can teach 
myself by playing around with it.  Could somebody give me some sample 
code for displaying a graph of the percentage of primes from, say, 1 to 
1000.  The x-axis would be the integers from 1 to 1000 and the y-axis 
would indicate the density of primes from 1 to n.  I can then figure out 
how to apply this code to other types of problems.

Really easy, since Mathematica already the built-in function PrimePi: 
PrimePi[n] is the number of primes less than or equal to n.

  ListPlot[Table[PrimePi[n]/n, {n, 1, 1000, 1}]]

(That calculates and plots the ratios as decimal fractions; of course 
just multiply by 100 for percentage.)


  Table[PrimePi[n]/n, {n, 1, 12, 1}]
{0, 1/2, 2/3, 1/2, 3/5, 1/2, 4/7, 1/2, 4/9, 2/5, 5/11, 5/12}

Murray Eisenberg                                     
murray at
Mathematics & Statistics Dept.      
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                  413 545-2859 (W)
710 North Pleasant Street                      fax   413 545-1801
Amherst, MA 01003-9305

  • Prev by Date: Re: Percentage of Primes
  • Next by Date: Re: Front end - Error when saving file
  • Previous by thread: Re: Percentage of Primes
  • Next by thread: Re: Percentage of Primes