Code covered by the BSD License  

Highlights from
List Factors

2.0

2.0 | 1 rating Rate this file 5 Downloads (last 30 days) File Size: 1.26 KB File ID: #18364

List Factors

by Jeff Miller

 

18 Jan 2008 (Updated 18 Jan 2008)

List all integer factors of a number

| Watch this File

File Information
Description

Takes a positive integer and lists all the positve integer factors of it in sorted order

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
19 Jan 2008 Jos x@y.z

The help should be improved. Add a H1 line, describe the expected input and output, give an example and add a See Also line.

The following two-liner will produce the same result:
f = x ./ [x:-1:1] ;
f = f(f==fix(f)).' ;

Its functionality is therefore quite trivial.

 

20 Jan 2008 Jiro Doke

Nice two-liner, Jos.
But note that this entry has memory and speed advantages. Try a large number, like 2^25.

20 Jan 2008 John D'Errico

A three liner then, that will be fairly efficient.

f = x ./(1:ceil(sqrt(x)));
f = f(f==fix(f)).' ;
f = unique([f;x./f]);

For example, when x = 2^25, the two liner takes
Elapsed time is 114.624158 seconds.

While my three liner takes only
Elapsed time is 0.139695 seconds.

20 Jan 2008 Jiro Doke

My hats off, John.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
factors Jeff Miller 22 Oct 2008 09:43:10
factorization Jeff Miller 22 Oct 2008 09:43:10
integer Jeff Miller 22 Oct 2008 09:43:10
number Jeff Miller 22 Oct 2008 09:43:10
all Jeff Miller 22 Oct 2008 09:43:10
list Jeff Miller 22 Oct 2008 09:43:10
sort Jeff Miller 22 Oct 2008 09:43:10

Contact us at files@mathworks.com