Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-252

Krylov Subspace Dimension

Problem

Return the dimension of the Krylov subspace spanned by v, A*v, A^2*v, ... for matrix A and starting vector v.

Add vectors until the rank of the collected set stops increasing, using a tolerance of 1e-9; the dimension is at most n.

Hint

The Krylov dimension is the degree of the minimal polynomial of A with respect to v.

Test cases

case 1
in: [[[2,0],[0,2]],[1,0]]
expected: 1
case 2
in: [[[0,1],[0,0]],[0,1]]
expected: 2
case 3
in: [[[1,0],[0,1]],[1,1]]
expected: 1
case 4
in: [[[2,0,0],[0,3,0],[0,0,4]],[1,1,1]]
expected: 3
Starter codePython
def krylov_dimension(A, v):
    # Your code here
    pass

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