Skip to content

How can I solve an underdetermined linear system? #489

Closed Answered by abdullahkhalids
abdullahkhalids asked this question in Q&A
Discussion options

You must be logged in to vote

Thank you for your quick answer. It gave me the necessary structure to be able to write a function to do the necessary. This seems to work.

I would appreciate if you glance at this and see if there are any obvious mistakes.

import numpy as np
import galois

def solve_underdetermined_system(A, b):
    n_vars = A.shape[1]
    A_rank = np.linalg.matrix_rank(A)
    
    # create augmented matrix
    Ab = np.hstack((A, np.atleast_2d(b).T))

    # Must be true for solutions to be consistent
    if A_rank != np.linalg.matrix_rank(Ab):
        return False, None

    # reduce the system
    Abrr = Ab.row_reduce()
    
    # additionally need reduced row echelon form (RREF)
    swaps = []
    for i 

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@mhostetter
Comment options

Answer selected by abdullahkhalids
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants