possible combination of a number

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

John D'Errico
John D'Errico il 1 Giu 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 Commento
Mohammad Sohel Rana
Mohammad Sohel Rana il 1 Giu 2018
Thank a lot for your help and good suggestions.
Kind regards Sohel

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by