Easy enough to do it with a loop. All that you need are the exponents. If you really want the symbolic forms later, trivial for that too.
function XT = xterms(N,nv)
XT = zeros(1,nv);
for n = 1:N
XTnew = zeros(0,nv);
for m = 1:nv
XTm = XT;
XTm(:,m) = XTm(:,m) + 1;
XTnew = [XTnew;XTm];
end
XT = unique(XTnew,'rows');
end
So:
xt = xterms(2,3)
xt =
0 0 2
0 1 1
0 2 0
1 0 1
1 1 0
2 0 0
If you want a symbolic form for each term, (it is a REALLY bad idea to create numbered variables, so I do not advise it.) But this is trivial too.
syms a1 a2 a3
prod(repmat([a1 a2 a3],size(xt,1),1).^xt,2)
ans =
a3^2
a2*a3
a2^2
a1*a3
a1*a2
a1^2
As I said, the exponent array is all that you really need for any computations.
Best Answer