Esempio n. 1
0
    def calculate_Gi_matrix(self, i):
        # 1) choose correct matrices for Gi[d/dt]
        # 2) change symbols to noncommutative symbols, calculate Gi[d/dt]
        # 3) G[d/dt] = G0[d/dt] * G1[d/dt] * ... * Gi[d/dt]
        # 4) special case procedure
        iteration = self._myStack.get_iteration(i)

        if not iteration.is_special_case:
            # get matrices
            P1_rpinv = iteration.P1_rpinv
            P1_roc = iteration.P1_roc
            B_lpinv = iteration.B_lpinv
            A = iteration.A

            P1_rpinv_nc, P1_roc_nc, B_lpinv_nc, A_nc = self.convert_to_nc_matrices(
                P1_rpinv, P1_roc, B_lpinv, A)

            Gi = P1_rpinv_nc - P1_roc_nc * (B_lpinv_nc * s_ +
                                            B_lpinv_nc * A_nc)

        else:
            # get matrices
            P1_rpinv = iteration.P1_rpinv
            P1_tilde_roc = iteration.P1_tilde_roc
            B_tilde_lpinv = iteration.B_tilde_lpinv
            A = iteration.A
            Z = iteration.Z

            # convert commutative symbols to non commutative
            P1_rpinv_nc = self.make_symbols_non_commutative(P1_rpinv)
            P1_tilde_roc_nc = self.make_symbols_non_commutative(P1_tilde_roc)
            B_tilde_lpinv_nc = self.make_symbols_non_commutative(B_tilde_lpinv)
            A_nc = self.make_symbols_non_commutative(A)
            Z_nc = self.make_symbols_non_commutative(Z)

            Gi = P1_rpinv_nc - P1_tilde_roc_nc * (B_tilde_lpinv_nc * s_ +
                                                  B_tilde_lpinv_nc * A_nc)

            Gi = st.concat_cols(Gi, Z_nc)

        if False:
            # show_Gi_matrices:
            pc.print_matrix("G", i, "", Gi)

        # store
        iteration.Gi = Gi

        return Gi
Esempio n. 2
0
    def calculate_Gi_matrix(self, i):
        # 1) choose correct matrices for Gi[d/dt]
        # 2) change symbols to noncommutative symbols, calculate Gi[d/dt]
        # 3) G[d/dt] = G0[d/dt] * G1[d/dt] * ... * Gi[d/dt]
        # 4) special case procedure
        iteration = self._myStack.get_iteration(i)

        if not iteration.is_special_case:
            # get matrices
            P1_rpinv = iteration.P1_rpinv
            P1_roc = iteration.P1_roc
            B_lpinv = iteration.B_lpinv
            A = iteration.A
            
            P1_rpinv_nc, P1_roc_nc, B_lpinv_nc, A_nc = self.convert_to_nc_matrices(P1_rpinv, P1_roc, B_lpinv, A)

            Gi = P1_rpinv_nc - P1_roc_nc*( B_lpinv_nc*s_ + B_lpinv_nc*A_nc )

        else:
            # get matrices
            P1_rpinv = iteration.P1_rpinv
            P1_tilde_roc = iteration.P1_tilde_roc
            B_tilde_lpinv = iteration.B_tilde_lpinv
            A = iteration.A
            Z = iteration.Z

            # convert commutative symbols to non commutative
            P1_rpinv_nc = self.make_symbols_non_commutative(P1_rpinv)
            P1_tilde_roc_nc = self.make_symbols_non_commutative(P1_tilde_roc)
            B_tilde_lpinv_nc = self.make_symbols_non_commutative(B_tilde_lpinv)
            A_nc = self.make_symbols_non_commutative(A)
            Z_nc = self.make_symbols_non_commutative(Z)

            Gi = P1_rpinv_nc - P1_tilde_roc_nc*( B_tilde_lpinv_nc*s_ + B_tilde_lpinv_nc*A_nc )

            Gi = st.concat_cols(Gi, Z_nc)

        if False:
            # show_Gi_matrices:
            pc.print_matrix("G", i, "", Gi)

        # store
        iteration.Gi = Gi

        return Gi
Esempio n. 3
0
def roc_hint(matrix_string, i,  matrix):
    error_string = "There must have been a mistake. Try again.\n"
    pc.print_matrix(matrix_string, i, "", matrix)
    while True:
        try:
            roc = eval(raw_input("Please enter " + str(matrix_string) + str(i) + "_roc or \"auto\":\n"))
            if roc==auto:
                roc = al.right_ortho_complement(matrix)
            try:
                if al.is_zero_matrix(matrix*roc):
                    pc.print_matrix(matrix_string, i, "_roc", roc)
                    return roc
                else:
                    print error_string
            except:
                print error_string
        except Exception as exc:
            print exc
            print error_string
Esempio n. 4
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
Esempio n. 5
0
def roc_hint(matrix_string, i, matrix):
    error_string = "There must have been a mistake. Try again.\n"
    pc.print_matrix(matrix_string, i, "", matrix)
    while True:
        try:
            roc = eval(
                input("Please enter " + str(matrix_string) + str(i) +
                      "_roc or \"auto\":\n"))
            if roc == auto:
                roc = al.right_ortho_complement(matrix)
            try:
                if al.is_zero_matrix(matrix * roc):
                    pc.print_matrix(matrix_string, i, "_roc", roc)
                    return roc
                else:
                    print(error_string)
            except:
                print(error_string)
        except Exception as exc:
            print(exc)
            print(error_string)
Esempio n. 6
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)
Esempio n. 7
0
    def print_stack(self):
        """ Prints all matrices for this iteration
        """
        pc.print_next_iteration(self.i)

        pc.print_matrix("P1", self.i, "", self.P1)
        pc.print_matrix("P0", self.i, "", self.P0)
        
        pc.print_matrix("P1", self.i, "_roc", self.P1_roc)
        pc.print_matrix("P1", self.i, "_rpinv", self.P1_rpinv)
        pc.print_matrix("P1", self.i, "_dot", self.P1_dot)

        pc.print_matrix("A", self.i, "", self.A)
        pc.print_matrix("B", self.i, "", self.B)
        pc.print_matrix("B", self.i, "_loc", self.B_loc)
        pc.print_matrix("B", self.i, "_lpinv", self.B_lpinv)
        
        if self.is_special_case:
            pc.print_special_case_line()

            pc.print_matrix("B", self.i, "_tilde", self.B_tilde)
            pc.print_matrix("B", self.i, "_tilde_lpinv", self.B_tilde_lpinv)
            pc.print_matrix("P1", self.i, "_tilde_roc", self.P1_tilde_roc)
            pc.print_matrix("Z", self.i, "", self.Z)
            pc.print_matrix("Z", self.i, "_lpinv", self.Z_lpinv)
Esempio n. 8
0
    def print_hint_stack(self):
        """ Prints remaining matrices in case of manual mode
        """
        pc.print_next_iteration(self.i)
        pc.print_matrix("P1", self.i, "_dot", self.P1_dot)

        pc.print_matrix("A", self.i, "", self.A)
        pc.print_matrix("B", self.i, "", self.B)
        pc.print_matrix("B", self.i, "_loc", self.B_loc)
        pc.print_matrix("B", self.i, "_lpinv", self.B_lpinv)
        
        if self.is_special_case:
            pc.print_special_case_line()

            pc.print_matrix("B", self.i, "_tilde", self.B_tilde)
            pc.print_matrix("B", self.i, "_tilde_lpinv", self.B_tilde_lpinv)
            pc.print_matrix("P1", self.i, "_tilde_roc", self.P1_tilde_roc)
            pc.print_matrix("Z", self.i, "", self.Z)
            pc.print_matrix("Z", self.i, "_lpinv", self.Z_lpinv)