How to find the pair of divisors which are closest in value for a non-prime number? If prime, how to do this for the next largest non-prime?
Show older comments
Case 1: I would like to find the largest two divsors, 'a' and 'b', of a non-prime integer, N such that N = a*b. For instance if N=24, I would like to a code that finds [a,b]=[4,6] not [a,b] = [2,12] etc.
Case 2: If N is prime, say N=11, how do I do this for the next non-prime number? so N=11->N=12 and [a,b] = [3,4].
(For context, I have a loop that generates a number of traces to be plotted where the value N is not known ahead of time. Sometimes N=3 and sometimes N=23. I'm trying to arrange the plots with subplot in a mostly 'square' arrangement that isn't just a skinny column or a skinny row. ).
2 Comments
David Goodmanson
on 24 Apr 2021
Hi Travis,
for n=14 for example, will 2x7 (which fits the rule) be all right, or would 3x5 be better? for n = 22 would 2x11 be all right, or would 4x6 be better?
Travis Briles
on 24 Apr 2021
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!