possible combination of a number
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Mohammad Sohel Rana
il 1 Giu 2018
Commentato: Mohammad Sohel Rana
il 1 Giu 2018
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.
0 Commenti
Risposta accettata
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.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!