So, I\'ve got X, a 300-by-1 vector and I\'d like [1, X, X*X, X*X*X, ... , X*X*...*X], a 300-by-twenty matrix.
How should I do this?
X=[2;1] [X,X.*X,X.*X
Use bsxfun for a neat solution, or go for Luis Mendo's extravaganza to save some time ;)
bsxfun
powers = 1:20; x = 1:20; result = bsxfun(@power,x(:),powers(:).');
gives:
1 1 1 ... 8 16 32 ... 27 81 243 ... 64 256 1024 ... ... ... ...