Need to test all permutations
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Say I have the following:
A = [1 2 3], B = [1 2], C = [4],
D = C + B*A
I need D to contain all permutations of C+B*A:
D1 = 4+1*1
D2 = 4+1*2
D3 = 4+1*3
D4 = 4+2*1
D5 = 4+2*2
D6 = 4+2*3
What is this called and what tools are available to perform this on bigger equations?
채택된 답변
Star Strider
2019년 4월 6일
A = [1 2 3];
B = [1 2];
C = [4];
[p1,p2,p3] = ndgrid(A,B,C);
P = [p3(:),p2(:),p1(:)]; % Components
D = p3(:) + p2(:).*p1(:)
The ‘P’ assignment simply displays the components used in the ‘D’ calculation. It is not otherwise necessary for the code.
I cannot guarantee that this will easily scale to other problems. It works here.
댓글 수: 6
CD
2019년 4월 6일
Star Strider,
Very nice example.
How would one expand/tweak your method to work with a numerator and denominator:
A = [1 2 3];
B = [1 2];
C = [4];
Num = C+A*B;
Den = C+A*B;
D = Num/Den;
D should be a column of all '1's.
And it is:
Num = p3(:) + p1(:).*p2(:);
Den = p3(:) + p1(:).*p2(:);
D = Num./Den
D =
1
1
1
1
1
1
CD
2019년 4월 6일
Star Strider,
Ok, the equation that I need to solve is pretty complicated.
Can your method be applied or do you recommend something else?
fs = 100000;
Ts = 1/fs;
Vref = 5;
Vo = Vref;
Vg = [22 32]
D = [Vo/Vg(1) Vo/Vg(2)]
Dp = 1-D
LL = 100e-6;
L = [(LL-LL*.1) LL (LL*.1+LL)]
Io = [2 4];
R = [(Vo/Io(1)) (Vo/Io(2))]
M1 = [(Vg(1)-Vo)/L(1) (Vg(1)-Vo)/L(2) (Vg(1)-Vo)/L(3) (Vg(2)-Vo)/L(1) (Vg(2)-Vo)/L(2) (Vg(2)-Vo)/L(3)]
M2 = [Vo/L(1) Vo/L(2) Vo/L(3)]
Ma = M2(2)
% Not real equations, numbers within "[]" represent row or element length
% Example M1 contains 6 elements, M2 contains 2 elements, together Fm should be a 6*3 or 18 element deep column
Fm = [1/((Ma+((M1[6]-M2[3])/2))*Ts);
% Ggo should be a 2*3*6*3*18*2*2 element deep column, I'm looking for the max value in this column
Gg0 = D[2]*(((2*Ma-M2[3])/(2*Ma+M1[6]-M2[3]))/(1+(Fm[18]*Vo)/(D[2]*R[2])));
Star Strider
2019년 4월 6일
I can’t understand your notation. My method might work, although I can’t guarantee it. I’m not certain how to construct the matrices for that calculation, since I don’t know how many would be required.
It might be best to use nested loops (or repeated bsxfun calls) for that, especially since the dimensions of the variables in the calculation are significantly different.
Star Strider
2019년 4월 6일
편집: Star Strider
2019년 4월 6일
Craig Dekker’s Answer moved to this Comment:
Thank you.
I'll try breaking the equation into several nested loops.
As always, my pleasure.
That may not be absolutely necessary.
I simply don’t understand your notation well enough to figure out how to use the ndgrid approach with it.
Experiment with something like this:
Dv1 = [1 2];
M2v1 = [3 4 5];
M1v1 = [6 7 8 9 10 11];
Fmv1 = (12:12+17);
Rv1 = [30 31];
[p1,p2,p3,p4,p5] = ndgrid(Dv1,M2v1,M1v1,Fmv1,Rv1);
Rv = p5(:);
Fmv = p4(:);
M1v = p3(:);
M2v = p2(:);
Dv = p1(:);
It seems that it might work, although I can’t guarantee it. I may also have missed something, since this code produces a series of (1296x1) vectors, while:
veclen = 2*3*6*3*18*2*2;
would have 7776 elements.
If the ndgrid approach works, it would definitely be faster than nested for loops. The challenge then comes in reshaping the output vector into a matrix that is meaningful in terms of the argument vectors. Appropriately indexing the result is the principal reason I would err on the side of the loops.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
