def reduction(iter_stack): P1i = iter_stack.P1 P0i = iter_stack.P0 P1i_roc = roc_hint( "P1", iter_stack.i, P1i) if mode == "manual" else al.right_ortho_complement(P1i) P1i_rpinv = rpinv_hint( "P1", iter_stack.i, P1i) if mode == "manual" else al.right_pseudo_inverse(P1i) P1i_dot = st.time_deriv(P1i, myStack.diffvec_x) Ai = al.custom_simplify((P0i - P1i_dot) * P1i_rpinv) Bi = al.custom_simplify((P0i - P1i_dot) * P1i_roc) if myStack.calc_G: Bi_lpinv = al.left_pseudo_inverse(Bi) else: Bi_lpinv = None # store iter_stack.store_reduction_matrices(Ai, Bi, Bi_lpinv, P1i_roc, P1i_rpinv, P1i_dot) return Bi
def reduction(iter_stack): P1i = iter_stack.P1 P0i = iter_stack.P0 P1i_roc = roc_hint("P1", iter_stack.i, P1i) if mode=="manual" else al.right_ortho_complement(P1i) P1i_rpinv = rpinv_hint("P1", iter_stack.i, P1i) if mode=="manual" else al.right_pseudo_inverse(P1i) P1i_dot = st.time_deriv(P1i, myStack.diffvec_x) Ai = al.custom_simplify( (P0i - P1i_dot)*P1i_rpinv ) Bi = al.custom_simplify( (P0i - P1i_dot)*P1i_roc ) if myStack.calc_G: Bi_lpinv = al.left_pseudo_inverse(Bi) else: Bi_lpinv = None # store iter_stack.store_reduction_matrices( Ai, Bi, Bi_lpinv, P1i_roc, P1i_rpinv, P1i_dot ) return Bi
def rpinv_hint(matrix_string, i, matrix): # TODO: check if this can somehow move to the algebra module # (problem: different namespace, so the algebra module won't # know about symbols and statevector) error_string = "There must have been a mistake. Try again.\n" while True: try: rpinv = eval(raw_input("Please enter " + str(matrix_string) + str(i) + "_rpinv or \"auto\":\n")) if rpinv==auto: rpinv = al.right_pseudo_inverse(matrix) try: if al.is_unit_matrix(matrix*rpinv): pc.print_matrix(matrix_string, i, "_rpinv", rpinv) return rpinv else: print error_string except: print error_string except Exception as exc: print exc print error_string
def rpinv_hint(matrix_string, i, matrix): # TODO: check if this can somehow move to the algebra module # (problem: different namespace, so the algebra module won't # know about symbols and statevector) error_string = "There must have been a mistake. Try again.\n" while True: try: rpinv = eval( input("Please enter " + str(matrix_string) + str(i) + "_rpinv or \"auto\":\n")) if rpinv == auto: rpinv = al.right_pseudo_inverse(matrix) try: if al.is_unit_matrix(matrix * rpinv): pc.print_matrix(matrix_string, i, "_rpinv", rpinv) return rpinv else: print(error_string) except: print(error_string) except Exception as exc: print(exc) print(error_string)