possible combination of a number

조회 수: 1 (최근 30일)
Mohammad Sohel Rana
Mohammad Sohel Rana 2018년 6월 1일
댓글: Mohammad Sohel Rana 2018년 6월 1일
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.
  댓글 수: 1
Mohammad Sohel Rana
Mohammad Sohel Rana 2018년 6월 1일
Thank a lot for your help and good suggestions.
Kind regards Sohel

댓글을 달려면 로그인하십시오.

추가 답변 (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