Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-121

Vandermonde Matrix

Problem

Build the Vandermonde matrix of the values x with n columns:

V[i][j] = x[i]^j for j = 0, ..., n - 1.

The first column is all ones, and each row is a geometric progression.

Hint

Vandermonde matrices appear when fitting polynomials to data points.

Test cases

case 1
in: [[1,2,3],3]
expected: [[1,1,1],[1,2,4],[1,3,9]]
case 2
in: [[0,1],2]
expected: [[1,0],[1,1]]
case 3
in: [[2],4]
expected: [[1,2,4,8]]
case 4
in: [[-1,0,1],3]
expected: [[1,-1,1],[1,0,0],[1,1,1]]
Starter codePython
def vandermonde_matrix(x, n):
    # Your code here
    pass

4 test cases · run your code against them in the editor