필터 지우기
필터 지우기

Obtaining n^th order polynomial combinations in an array

조회 수: 2 (최근 30일)
Shreshtha Chaturvedi
Shreshtha Chaturvedi 2022년 12월 20일
편집: KSSV 2022년 12월 20일
Hi, I want to obtain an array consisting of all the possible combinations of polynomials upto n^(th) order. For example, for order 2, the array would look like
[1, x(1), x(2), x(3), x(4), x(5), x(6), x(1)*x(1), x(1)*x(2), x(1)*x(3), x(1)*x(4), x(1)*x(5), x(1)*x(6), x(2)*x(2), x(2)*x(3), x(2)*x(4), x(2)*x(5), x(2)*x(6), x(3)*x(3), x(3)*x(4), x(3)*x(5), x(3)*x(6), x(4)*x(4), x(4)*x(5), x(4)*x(6), x(5)*x(5),x(5)*x(6), x(6)*x(6)]
Whereas for order 3, it will look like
[1, x(1), x(2), x(3), x(4), x(5), x(6), x(1)*x(1), x(1)*x(2), x(1)*x(3), x(1)*x(4), x(1)*x(5),
x(1)*x(6), x(2)*x(2), x(2)*x(3), x(2)*x(4), x(2)*x(5), x(2)*x(6), x(3)*x(3), x(3)*x(4),
x(3)*x(5), x(3)*x(6), x(4)*x(4), x(4)*x(5), x(4)*x(6), x(5)*x(5),x(5)*x(6),
x(6)*x(6), x(1)*x(1)*x(1), x(1)*x(1)*x(2), x(1)*x(1)*x(3), x(1)*x(1)*x(4),
x(1)*x(1)*x(5), x(1)*x(1)*x(6), x(1)*x(2)*x(2), x(1)*x(2)*x(3), x(1)*x(2)*x(4),
x(1)*x(2)*x(5), x(1)*x(2)*x(6), x(1)*x(3)*x(3), x(1)*x(3)*x(4), x(1)*x(3)*x(5),
x(1)*x(3)*x(6), x(1)*x(4)*x(4), x(1)*x(4)*x(5), x(1)*x(4)*x(6), x(1)*x(5)*x(5),
x(1)*x(5)*x(6), x(1)*x(6)*x(6), x(2)*x(2)*x(2), x(2)*x(2)*x(3), x(2)*x(2)*x(4),
x(2)*x(2)*x(5), x(2)*x(2)*x(6),x(2)*x(3)*x(3), x(2)*x(3)*x(4), x(2)*x(3)*x(5), x(2)*x(3)*x(6),
x(2)*x(4)*x(4), x(2)*x(4)*x(5), x(2)*x(4)*x(6), x(2)*x(5)*x(5), x(2)*x(5)*x(6), x(2)*x(6)*x(6),
x(3)*x(3)*x(3),x(3)*x(3)*x(4), x(3)*x(3)*x(5), x(3)*x(3)*x(6), x(3)*x(4)*x(4), x(3)*x(4)*x(5),
x(3)*x(4)*x(6), x(3)*x(5)*x(5), x(3)*x(5)*x(6), x(3)*x(6)*x(6), x(4)*x(4)*x(4), x(4)*x(4)*x(5),
x(4)*x(4)*x(6), x(4)*x(5)*x(5),x(4)*x(5)*x(6), x(4)*x(6)*x(6), x(5)*x(5)*x(5), x(5)*x(5)*x(6),
x(5)*x(6)*x(6), x(6)*x(6)*x(6)]
So far, I am manually defining such arrays, but as you can see, it is very tedious. Is there a way to code this for any random order n? Thank you for all the help!

답변 (1개)

KSSV
KSSV 2022년 12월 20일
편집: KSSV 2022년 12월 20일
REad about nchoosek
You may also refer to the below file exchange: https://in.mathworks.com/matlabcentral/fileexchange/9029-nmultichoosek

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by