possible combination of a number

1 view (last 30 days)
Hi, I am seeking help to find all possible combination of number in Matlab. Cosider A=[1,2,......50]; B=[50,49,.....1]; Conditions A*B=50;
Then A1 and B1 will new values based on the condition. A1=[1,2,5,10,25,50] B1=[50,25,5,2,1] How I can solve this in Matlab.
Thank you.

Accepted Answer

John D'Errico
John D'Errico on 1 Jun 2018
The trivial solution:
loc = A.*B == 50;
A1 = A(loc);
B1 = B(loc);
No, I won't show you how to solve this for significantly LARGE numbers, since you need to learn MATLAB, and how to use the tools in MATLAB to advantage. If I write basic code for you, then you learn nothing.
So you need to learn to use tools like factor. Once you have the factors of a number, you can create a list of all distinct integer divisors.
What property do all divisors of the number 1234567890 have? Think about how this will help you:
factor(1234567890)
ans =
2 3 3 5 3607 3803
What can you do with that list?
unique(kron([1 2],[1 3 9]))
ans =
1 2 3 6 9 18
How can that idea be used to extend the list of divisors?
If this is homework, then to start, you might want to learn how to factor an integer.
  1 Comment
Mohammad Sohel Rana
Mohammad Sohel Rana on 1 Jun 2018
Thank a lot for your help and good suggestions.
Kind regards Sohel

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!