Efficient creation of power series matrix or array of arrays

First, the code you quoted (remember to quote your code!) isn’t correct: you can’t create an array with Array(m,n) because you have to give an element type. In this case, since you probably want to have the same element type as x, you could change the line V = Array(m, n) to

V = similar(x, m, n)

Then you call it by passing an array (for the x) argument, and it makes a Vandermonde matrix from that array, for example:

julia> matrix_vandermonde([1,2,3,4])
4×4 Array{Int64,2}:
 1  1   1   1
 1  2   4   8
 1  3   9  27
 1  4  16  64
2 Likes