possible combination of a number

1 次查看(过去 30 天)
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.

采纳的回答

John D'Errico
John D'Errico 2018-6-1
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by