Experimentally determining computational complexity of the matrix determinant

I need help experimentally determining the computational complexity of the determinant of the matrix nxn

My code is:

    import numpy as np
    import timeit
    t0 = time.time()
    for n in range(1, 10):
        A = np.random.rand(n, n)
        det = np.linalg.slogdet(A)
        t = timeit.timeit(lambda: det)
        print(t)

But I get the same time for every n, therefore, computational complexity: O (N), which is incorrect, since it must be O (N ^ 3). Any help would be greatly appreciated.

+4
source share
1 answer

, , N, - . 10x10 , . 100, 1000, 10000 .., .

,

for n in range(1, 14):
    t0 = time.time()
    p = 2**n
    A = np.random.rand(p,p)
    det = np.linalg.slogdet(A)
    print('N={:04d} : {:.2e}s'.format(p, time.time() - t0))

N=0002 : 4.35e-02s
N=0004 : 0.00e+00s
N=0008 : 0.00e+00s
N=0016 : 5.02e-04s
N=0032 : 0.00e+00s
N=0064 : 5.02e-04s
N=0128 : 5.01e-04s
N=0256 : 1.50e-03s
N=0512 : 8.00e-03s
N=1024 : 3.95e-02s
N=2048 : 2.05e-01s
N=4096 : 1.01e+00s
N=8192 : 7.14e+00s

, N O(), N .

+2

Source: https://habr.com/ru/post/1661254/


All Articles