Skip to content

Instantly share code, notes, and snippets.

@sengupta
Created May 8, 2011 18:39
Show Gist options
  • Save sengupta/961582 to your computer and use it in GitHub Desktop.
Save sengupta/961582 to your computer and use it in GitHub Desktop.
Three ways of generating a Vandermonde matrix
// Three ways of generating a Vandermonde matrix:
function y = vandermonde1(x)
n = length(x)
for i = 1:n
y(:, i) = x^(i-1)
end
endfunction
function y = vandermonde2(a)
n = length(a)
y=[a*ones(1,4)].^[[0:n-1]'*ones(1,4)]'
endfunction
function y = vandermonde3(a)
n = length(a)
y = kron(a, ones(1, n)).^kron([0:n-1]', ones(1, n))'
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment