Play into the world of prime numbers!


Updated 15 Mar 2018

From GitHub

View License on GitHub

Primespiral is a function to explore the distribution of prime numbers arranged into a spiral pattern.
The well-known Ulam spiral and the variant developed by Robert Sacks,
the Sacks spiral, show interesting geometric patterns in the positions of primes.
Syntax: primesout=primespiral(t)

t - is an integer number. The spiral will be plotted between 0 and t
If t is omitted, it will be set to 3571 (between 0 and 3571
there are 500 prime numbers).
primesout - the primes of the choosed family, between 0 and t.

The function will ask if you want to use the Ulam, Sacks, Vogel or Archimede spiral.
Then it will ask if you want to highlight a particular prime family.

The primes of the family you choosed between 0 and t

Created by Giuseppe Cardillo

To cite this file, this would be an appropriate format:
Cardillo G. (2014) Primespiral: Play into the world of prime numbers!

Cite As

Giuseppe Cardillo (2023). Primespiral (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Number games in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes

each plot contains two boxes with descriptions of chosen spiral and prime family
Github link

The function is more compact and rational.
Archimede spiral was added (to shows that prime numbers greater then 7 have 1, 3, 7 or 9 as last digit)

some minor bugs correction and new primes families added

some other primes families were added

Ulam Spiral added;
more simplex algorithm

bug correction in Dihedral primes computation; minimal primes added

change in help section to correctly cite the file

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.