def matrix_find_eigenvalues(matrix):
    eigenvalues = []
    eigenvalues.append(
        matrix_inverse_power_iteration(matrix, 0.0, 0.00000000000001, 20000))
    eigenvalues.append(matrix_power_iteration(matrix, 0.0000000001, 20000))
    find_middle_eigenvalue(matrix, eigenvalues, eigenvalues[0], eigenvalues[1])
    return eigenvalues
def find_middle_eigenvalue(matrix, eigenvalues, min_value, max_value):
    middle = (max_value + min_value) / 2
    middle_eigenvalue, count = matrix_inverse_power_iteration(
        matrix, middle, 0.00000000000001, 1000, getIterCount=True)
    if (
            count != 1000
    ):  #If no convergence happens after 1000 iterations, then middle is probably right inbetween the only 2 eigenvalues.
        if (not abs(middle_eigenvalue - min_value) < 0.0001) and (
                not abs(middle_eigenvalue - max_value) < 0.0001):
            eigenvalues.append(middle_eigenvalue)
            find_middle_eigenvalue(matrix, eigenvalues, min_value,
                                   middle_eigenvalue)
            find_middle_eigenvalue(matrix, eigenvalues, middle_eigenvalue,
                                   max_value)
def hilbert_matrix_inverse_power_iteration_test():

    selection = [4, 6, 8, 10]
    hilbert_matrix = []
    solution = []

    # Create the hilbert matrices and their corresponding Q factorization matrix.
    for n in selection:
        hilbert_matrix.append([[1 / (1 + i + j) for i in range(n)]
                               for j in range(n)])  # Hilbert Matrix generator
        solution.append(
            matrix_inverse_power_iteration(hilbert_matrix[-1], 0,
                                           0.0000000000001, 100000))

    for i in range(0, len(selection)):  # 4, 6, 8, 10
        print("Smallest Eigenvalue for " + str(selection[i]) + "x" +
              str(selection[i]) + ": " + str(solution[i]))
Ejemplo n.º 4
0
def matrix_inverse_iteration_rayleigh_quotient_compare():
    for i in [10, 50, 100, 200]:
        matrix = gen_sqr_diagdom_matrix(i)
        #vector = [1]*i
        starttime = time.time()
        solution, count = matrix_inverse_power_iteration(matrix,
                                                         0,
                                                         0.0001,
                                                         10000,
                                                         getIterCount=True)
        print(
            str(i) + "x" + str(i) + " Inverse_Power: Time: " +
            str(time.time() - starttime) + ", Iteration Count: " + str(count))
        starttime = time.time()
        solution, count = matrix_rayleigh_quotient_iteration(matrix,
                                                             0.0001,
                                                             10000,
                                                             getIterCount=True)
        print(
            str(i) + "x" + str(i) + " Rayleigh Quotient: Time: " +
            str(time.time() - starttime) + ", Iteration Count: " + str(count))
def matrix_condition_number(matrix):
    smallest_eigenvalue = matrix_inverse_power_iteration(
        matrix, 0, 0.00000000000001, 20000)
    largest_eigenvalue = matrix_power_iteration(matrix, 0.0000000001, 20000)
    return abs(largest_eigenvalue / smallest_eigenvalue)
Ejemplo n.º 6
0
def matrix_condition_number(matrix):
    largest_eigenvalue = matrix_rayleigh_quotient_iteration(
        matrix, 0.00000000000001, 20000)
    smallest_eigenvalue = matrix_inverse_power_iteration(
        matrix, 0, 0.0000000001, 20000)
    return abs(largest_eigenvalue / smallest_eigenvalue)