File Exchange

image thumbnail

Vandermonde matrix, vander() function extension

version 1.1 (1.29 KB) by

Adds functionality to the original MATLAB vander() function.



View License

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.

Comments and Ratings (3)

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...

John D'Errico

John D'Errico (view profile)

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.

Jan Simon

Jan Simon (view profile)

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).
Replaced for-loop by bsxfun.

MATLAB Release
MATLAB 8.2 (R2013b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video