Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11860
| From | Murray Eisenberg <murray@math.umass.edu> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Percentage of Primes |
| Date | 2012-09-23 07:16 +0000 |
| Message-ID | <k3md0q$795$1@smc.vnet.net> (permalink) |
| References | <20120922064747.0DFD4685F@smc.vnet.net> |
| Organization | Time-Warner Telecom |
On Sep 22, 2012, at 2:47 AM, Jared E <eggers.jared@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[12]
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@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
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Percentage of Primes Murray Eisenberg <murray@math.umass.edu> - 2012-09-23 07:16 +0000
csiph-web