Perfect Number Generator

Finds even perfect numbers [ppN(:,3)] for each relevant prime <= P.
517 Downloads
Updated 12 Jan 2010

View License

It calculates perfect even #'s with 2^(p-1)*(2^p - 1) where p and (2^p - 1)
%are prime. A subsequent run yields a faster run-time. The code is fully
%vectorized and hence cleaner than previous versions of the function.
%NB: if (2^p - 1) is a Mersenne prime then a perfect number has been found.
%
%SYNTAX: >> perf_finalv4(P) % where P is an integer scalar in
%useful inclusive range [2..31].
%i.e. run showing first 8 perfect numbers...
%>> p = perf_finalv4(31);
%>> [p(:,3)]
%
% ans =
%
% 6
% 28
% 496
% 8128
% 33550336
% 8589869056
% 137438691328
% 2.30584300813995e+018

Cite As

Bruce Raine (2024). Perfect Number Generator (https://www.mathworks.com/matlabcentral/fileexchange/26314-perfect-number-generator), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Discrete Math 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!
Version Published Release Notes
1.3.0.0

Corrected comments in function header i.e.
%2^43,112,608 × (2^43,112,609 - 1)
and also spelling typo. NB: neither change affects the function's performance.

1.0.0.0