Think we have few strams. n cold and m hot. How many cases are possible that they can face each other?
I want to program it on matlab,and save all cases in another matrix,then use that matrix as a feed of another operation.
Anyone knows how write it on matlab?
I’m not sure but I think for 2 cold and 2 hot strams there is 4 cases possible like below:

댓글 수: 4

Torsten
Torsten 2019년 4월 23일
There are n! possibilities to order the cold streams and m! possibilities to order the hot streams. Thus there should be n! * m! possibilities they can face each other, I guess.
Amy Hs
Amy Hs 2019년 4월 23일
편집: Amy Hs 2019년 4월 23일
thanks,
yeah I know, but I want all those cases,like:
Data1=[H1 H2];Data=[C1 C2] % matlab read these initial data from excel file
A{1}=[H1 H2] ; B{1}=[C1 C2] %step 1
A{2}=[H2 H1] ; B{2}=[C2 C1]
so
A involves all possible case of Hot streams
B involves all possible case of Hot streams
then I could face them to each other by a simple (2d for) loops,
problem is step 1,
i know there are n! for cold and m! for hot ,but i dont know how save all cases in a greater matrix because i need them,
you can compute all the permutations using perms. So
perms(1:3)
ans =
3 2 1
3 1 2
2 3 1
2 1 3
1 3 2
1 2 3
Beware that the result of perms will get huge for large n. And if you are then wanting to compute all combinations of two sets, that gets even more huge.
So if n=m=10, means you apparently want to compute an array that is effectively of size n!*m!*(n+m).
S = factorial(10)*factorial(10)*20
S =
2.6336e+14
If each element is a double, that would be on the order of 2.1e6 gigabyes of RAM to store. So 2.1 petabytes?
Many times people want to do things that are computationally impossible, generating all such combinations. This is usually a signal they are trying to use a brute force way to compute a solution. At the same time, much of mathematics is devoted to finding alternative ways to avoid the need for brute force. For example, there are integer programming solvers that solve a problem without investigating every possible set of permissible solutions. So if your goal is to do this for large problems, I would suggest you look for alternatives. While brute force is indeed a possible approach, it is rarely a happy one for really large problems.
Amy Hs
Amy Hs 2019년 4월 23일
thanks a lot
for both your answer and your advice

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

답변 (0개)

제품

릴리스

R2016a

질문:

2019년 4월 23일

댓글:

2019년 4월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by