Commit 8c9733ed authored by Blais, Chris's avatar Blais, Chris
Browse files

added funcs for analyzing jacobian

parent 17fc905e
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
# helper functions for analyzing jacobian, rref, etc
import sympy as sy



def make_rhs(jac):
    """ 
    make the rhs for the rref operations. facile way to show the row operations 
    if used with sympy.rref_rhs. 
    """
    syms = []
    for row in range(1, jac.rows+1):
        syms.append(sy.Symbol(f"r{row}"))
    
    rhs = sy.Matrix(syms)
    return rhs

def exclude_rows(matrix, rows_to_exclude):
    """
    Create new matrix excluding specified rows
    
    Args:
        matrix: sympy Matrix
        rows_to_exclude: list or set of row indices to exclude
    
    Returns:
        New sympy Matrix with specified rows removed
    """
    if isinstance(rows_to_exclude, int):
        rows_to_exclude = {rows_to_exclude}
    else:
        rows_to_exclude = set(rows_to_exclude)
    
    # Validate row indices
    if any(row >= matrix.rows or row < 0 for row in rows_to_exclude):
        raise ValueError("Row index out of bounds")
    
    kept_rows = [matrix.row(i) for i in range(matrix.rows) 
                 if i not in rows_to_exclude]
    
    return sy.Matrix(kept_rows) if kept_rows else sy.Matrix(0, matrix.cols, [])
 No newline at end of file