From: M Mouse on
hey,
I know this is a general math problem, but I was wondering if there
was a spiffy matlab way of doing it...
say I have a number X and I want to find three other numbers (a, b,
c) such that when they are multiplied together they equal X.
a*b*c=X
I want to generate a list of all possibilities of a, b, and c for a
given X.
Is there an easy way to change this to find four (or five or six)
numbers?
I know this problem is a general 'finding primes' type of question,
but in my case all my values for X are 'small' (less than 500)...
Thanks in advance...
From: Jos on
M Mouse wrote:
>
>
> hey,
> I know this is a general math problem, but I was wondering if there
> was a spiffy matlab way of doing it...
> say I have a number X and I want to find three other numbers (a, b,
> c) such that when they are multiplied together they equal X.
> a*b*c=X
> I want to generate a list of all possibilities of a, b, and c for a
> given X.
> Is there an easy way to change this to find four (or five or six)
> numbers?
> I know this problem is a general 'finding primes' type of question,
> but in my case all my values for X are 'small' (less than 500)...
> Thanks in advance...

Let N be your number and M the number of "factors"".

Then:

p = perms(factor(N)) ;
if length(p) >= M,
y = unique([p(:,1:M-1) prod(p(:,M:end),2)],'rows') ;
else
error('No solution')
end

will do the job.

hth
Jos
From: Paul Skoczylas on
"M Mouse" <minnieM(a)mailinator.com> wrote in message news:ef121e5.-1(a)webx.raydaftYaTP...
> hey,
> I know this is a general math problem, but I was wondering if there
> was a spiffy matlab way of doing it...
> say I have a number X and I want to find three other numbers (a, b,
> c) such that when they are multiplied together they equal X.
> a*b*c=X
> I want to generate a list of all possibilities of a, b, and c for a
> given X.
> Is there an easy way to change this to find four (or five or six)
> numbers?
> I know this problem is a general 'finding primes' type of question,
> but in my case all my values for X are 'small' (less than 500)...
> Thanks in advance...

"factor" will find all the prime factors of a number. That's somewhere for you to start, anyway...

-Paul


From: Jos on
Jos wrote:
>
>
> M Mouse wrote:
>>
>>
>> hey,
>> I know this is a general math problem, but I was wondering if
> there
>> was a spiffy matlab way of doing it...
>> say I have a number X and I want to find three other numbers
(a,
> b,
>> c) such that when they are multiplied together they equal X.
>> a*b*c=X
>> I want to generate a list of all possibilities of a, b, and c
for
> a
>> given X.
>> Is there an easy way to change this to find four (or five or
six)
>> numbers?
>> I know this problem is a general 'finding primes' type of
> question,
>> but in my case all my values for X are 'small' (less than
500)...
>> Thanks in advance...
>
> Let N be your number and M the number of "factors"".
>
> Then:
>
> p = perms(factor(N)) ;
> if length(p) >= M,
> y = unique([p(:,1:M-1) prod(p(:,M:end),2)],'rows') ;
> else
> error('No solution')
> end
>
> will do the job.
>
> hth
> Jos

A sort was missing to eliminate duplicates:

p = perms(factor(N)) ;
if length(p) >= M,
y = unique(sort([p(:,1:M-1) prod(p(:,M:end),2)],2),'rows') ;
else
error('No solution')
end

Jos
From: Jos on
Jos wrote:
>
>
> Jos wrote:
>>
>>
>> M Mouse wrote:
>>>
>>>
>>> hey,
>>> I know this is a general math problem, but I was wondering
if
>> there
>>> was a spiffy matlab way of doing it...
>>> say I have a number X and I want to find three other
numbers
> (a,
>> b,
>>> c) such that when they are multiplied together they equal
X.
>>> a*b*c=X
>>> I want to generate a list of all possibilities of a, b, and
c
> for
>> a
>>> given X.
>>> Is there an easy way to change this to find four (or five
or
> six)
>>> numbers?
>>> I know this problem is a general 'finding primes' type of
>> question,
>>> but in my case all my values for X are 'small' (less than
> 500)...
>>> Thanks in advance...
>>
>> Let N be your number and M the number of "factors"".
>>
>> Then:
>>
>> p = perms(factor(N)) ;
>> if length(p) >= M,
>> y = unique([p(:,1:M-1) prod(p(:,M:end),2)],'rows') ;
>> else
>> error('No solution')
>> end
>>
>> will do the job.
>>
>> hth
>> Jos
>
> A sort was missing to eliminate duplicates:
>
> p = perms(factor(N)) ;
> if length(p) >= M,
> y = unique(sort([p(:,1:M-1) prod(p(:,M:end),2)],2),'rows') ;
> else
> error('No solution')
> end
>
> Jos

ahum ... on testing this function it fails in some occasions, e.g.
when N=32 and M=3 ...

Jos