예제 #1
0
def matrix_solve_LU(matrix, vector):
    temp_list = matrix_LU_factor(matrix)
    matrix_l = temp_list[0]
    matrix_u = temp_list[1]
    solution_y = matrix_solve_lower_tri(matrix_l, vector)
    solution_x = matrix_solve_upper_tri(matrix_u, solution_y)
    return solution_x
예제 #2
0
def matrix_solve_least_square_normal(matrix,vector):
    vector = [[vector[i]] for i in range(len(vector))]
    matrix_A_At = matrix_mult(matrix_transpose(matrix),matrix)
    vector_At_b = matrix_mult(matrix_transpose(matrix),vector)
    matrix_G = matrix_cholesky_fac(matrix_A_At)
    vector_y = matrix_solve_lower_tri(matrix_G,matrix_transpose(vector_At_b)[0])
    vector_x = matrix_solve_upper_tri(matrix_transpose(matrix_G),vector_y)
    return vector_x
예제 #3
0
def matrix_solve_least_squares_QR(matrix,vector):
    (matrix_Q, matrix_R) = matrix_QR_factorization_mod(matrix)
    print(matrix_Q)
    print(matrix_R)
    matrix_Qtb = matrix_mult(matrix_transpose(matrix_Q), convert_vec_mat(vector))
    print(matrix_Qtb)
    solution = matrix_solve_upper_tri(matrix_R, convert_vec_mat(matrix_Qtb))
    print(solution)
    return solution
def matrix_solve_LU_scaled_partial_pivoting(matrix, vector):
    n = len(matrix)
    LU = matrix_LU_factor_scaled_partial_pivoting(matrix)
    U = [[(LU[i][j] if (i <= j) else 0.0) for j in range(n)] for i in range(n)]
    L = [[(LU[i][j] if (i > j) else (1.0 if (i == j) else 0.0))
          for j in range(n)] for i in range(n)]

    solution_y = matrix_solve_lower_tri(L, vector)
    solution_x = matrix_solve_upper_tri(U, solution_y)
    return solution_x
예제 #5
0
def matrix_solve(matrix, vector):
    n = len(matrix)
    solution = [0] * len(vector)
    for i in range(n):
        matrix[i].append(vector[i])
    ref_matrix = matrix_ref(matrix)
    for i in range(n):
        solution[i] = ref_matrix[i][-1]
        del ref_matrix[i][-1]

    solution = matrix_solve_upper_tri(ref_matrix, solution)

    return solution
예제 #6
0
def matrix_solve_least_squares_QR_householder(matrix, vector):
    (matrix_Q, matrix_R) = matrix_QR_factorization_householder(matrix)
    matrix_Qtb = matrix_mult(matrix_transpose(matrix_Q),
                             convert_vec_mat(vector))
    solution = matrix_solve_upper_tri(matrix_R, convert_vec_mat(matrix_Qtb))
    return solution
예제 #7
0
def matrix_solve_QR_factorization(matrix, vector):
    (matrix_Q, matrix_R) = matrix_QR_factorization(matrix)
    matrix_Qtb = matrix_mult(matrix_transpose(matrix_Q),
                             convert_vec_mat(vector))
    solution = matrix_solve_upper_tri(matrix_R, convert_vec_mat(matrix_Qtb))
    return solution