Uses the more common definition of the Vandermonde matrix with power zero to the left, and adds the ability to create non-square matrices for more flexibility.
V=vander2(v,k)=[v.^0 v.^1 ... v.^k];
where length(v)=n and dim(V)=[n, k].
Note that replacing the original vander() function can cause other functions to fail.
Thanks for the comments guys! Indeed, its a bad idea to REPLACE vander with this function, so I changed the name and made a note in the text. However, one of the points was to use the normal definition, so I won't change that. I also added bsxfun instead of the for-loop, that was just bad...
The code uses a loop to build the array too. Simple enough is just:
A = bsxfun(@power,v(:),k:-1:0);
No preallocation is even needed.
This also fixes the problem that Jan points out, i.e., that this tool as it currently is will totally break any code that assumed the order from the original gander. That is indeed a serious flaw. Do yourself a favor, and do NOT download this tool until the author is willing to update it to function correctly.
It is a very bad idea to shadow the original function "vander" by this version. The new feature, which allows the specification of the number of columns might be useful, but the order of columns has changed. In consequence several toolbox functions will reply wrong results.
Changed function name to vander2 not to replace original (since the output is changed).
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.