       Re: Percentage of Primes

• To: mathgroup at smc.vnet.net
• Subject: [mg128193] Re: Percentage of Primes
• From: Murray Eisenberg <murray at math.umass.edu>
• Date: Sun, 23 Sep 2012 02:59:13 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net
• References: <20120922064747.0DFD4685F@smc.vnet.net>

```On Sep 22, 2012, at 2:47 AM, Jared E <eggers.jared at gmail.com> 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.)

Explanation:

PrimePi
5

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 math.umass.edu
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