Clear Filters
Clear Filters

Obtaining n^th order polynomial combinations in an array

2 views (last 30 days)
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!

Answers (1)

KSSV
KSSV on 20 Dec 2022
Edited: KSSV on 20 Dec 2022
REad about nchoosek
You may also refer to the below file exchange: https://in.mathworks.com/matlabcentral/fileexchange/9029-nmultichoosek

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!