Beispiel #1
0
def fourseven(iter_stack):
    # load matrices
    Ai = iter_stack.A
    Bi = iter_stack.B
    P1i_roc = iter_stack.P1_roc
    P1i_rpinv = iter_stack.P1_rpinv
    
    K2 = roc_hint("B", iter_stack.i, Bi) if mode=="manual" else al.right_ortho_complement(Bi)

    K1 = al.regular_completion(K2)

    K = st.concat_cols(K1, K2)

    assert al.is_regular_matrix(K), "K is not a regular matrix."

    Bi_tilde = al.custom_simplify(Bi*K1) # unit matrix

    if myStack.calc_G:
        Bi_tilde_lpinv = al.left_pseudo_inverse(Bi_tilde)
    else:
        Bi_tilde_lpinv = None

    P1i_tilde_roc = al.custom_simplify( P1i_roc*K1 )

    Zi = al.custom_simplify( P1i_roc*K2 )

    Zi_lpinv = al.Zi_left_pinv_with_restrictions(P1i_rpinv, P1i_tilde_roc, Zi)

    assert al.is_unit_matrix( Zi_lpinv*Zi ), "Zi_lpinv seems to be wrong."

    # store
    iter_stack.store_special_case_matrices( Zi, Zi_lpinv, Bi_tilde, Bi_tilde_lpinv, P1i_tilde_roc )

    return Bi_tilde
Beispiel #2
0
def lpinv_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:
            lpinv = eval(raw_input("Please enter " + str(matrix_string) + str(i) + "_lpinv or \"auto\":\n"))
            if lpinv==auto:
                lpinv = al.left_pseudo_inverse(matrix)
            try:
                if al.is_unit_matrix(lpinv*matrix):
                    pc.print_matrix(matrix_string, i, "_lpinv", lpinv)
                    return lpinv
                else:
                    print error_string
            except:
                print error_string
        except Exception as exc:
            print exc
            print error_string
Beispiel #3
0
def lpinv_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:
            lpinv = eval(
                input("Please enter " + str(matrix_string) + str(i) +
                      "_lpinv or \"auto\":\n"))
            if lpinv == auto:
                lpinv = al.left_pseudo_inverse(matrix)
            try:
                if al.is_unit_matrix(lpinv * matrix):
                    pc.print_matrix(matrix_string, i, "_lpinv", lpinv)
                    return lpinv
                else:
                    print(error_string)
            except:
                print(error_string)
        except Exception as exc:
            print(exc)
            print(error_string)
Beispiel #4
0
def fourseven(iter_stack):
    # load matrices
    Ai = iter_stack.A
    Bi = iter_stack.B
    P1i_roc = iter_stack.P1_roc
    P1i_rpinv = iter_stack.P1_rpinv

    K2 = roc_hint("B", iter_stack.i,
                  Bi) if mode == "manual" else al.right_ortho_complement(Bi)

    K1 = al.regular_completion(K2)

    K = st.concat_cols(K1, K2)

    assert al.is_regular_matrix(K), "K is not a regular matrix."

    Bi_tilde = al.custom_simplify(Bi * K1)  # unit matrix

    if myStack.calc_G:
        Bi_tilde_lpinv = al.left_pseudo_inverse(Bi_tilde)
    else:
        Bi_tilde_lpinv = None

    P1i_tilde_roc = al.custom_simplify(P1i_roc * K1)

    Zi = al.custom_simplify(P1i_roc * K2)

    Zi_lpinv = al.Zi_left_pinv_with_restrictions(P1i_rpinv, P1i_tilde_roc, Zi)

    assert al.is_unit_matrix(Zi_lpinv * Zi), "Zi_lpinv seems to be wrong."

    # store
    iter_stack.store_special_case_matrices(Zi, Zi_lpinv, Bi_tilde,
                                           Bi_tilde_lpinv, P1i_tilde_roc)

    return Bi_tilde