Ticket #3794: eigenfunctions-2.patch

File eigenfunctions-2.patch, 7.9 kB (added by jason, 5 months ago)
  • a/sage/matrix/matrix2.pyx

    old new  
    24482448        If algebraic_multiplicity=True, return a list of pairs 
    24492449             (e, V, n) 
    24502450        where e and V are as above and n is the algebraic multiplicity 
    2451         of the eigenvalue.  If the eigenvalue is a root of a 
    2452         polynomial, then the algebraic multiplicity is for each root 
    2453         separately. 
     2451        of the eigenvalue.  If the eigenvalues are given symbolically, 
     2452        as roots of an irreducible factor of the characteristic 
     2453        polynomial, then the algebraic multiplicity returned is the 
     2454        multiplicity of each conjugate eigenvalue. 
    24542455 
    24552456        The eigenspaces are returned sorted by the corresponding characteristic 
    24562457        polynomials, where polynomials are sorted in dictionary order starting 
     
    26482649        If algebraic_multiplicity=True, return a list of pairs 
    26492650             (e, V, n) 
    26502651        where e and V are as above and n is the algebraic multiplicity 
    2651         of the eigenvalue.  If the eigenvalue is a root of a 
    2652         polynomial, then the algebraic multiplicity is for each root 
    2653         separately. 
     2652        of the eigenvalue.  If the eigenvalues are given symbolically, 
     2653        as roots of an irreducible factor of the characteristic 
     2654        polynomial, then the algebraic multiplicity returned is the 
     2655        multiplicity of each conjugate eigenvalue. 
    26542656         
    26552657        The eigenspaces are returned sorted by the corresponding characteristic 
    26562658        polynomials, where polynomials are sorted in dictionary order starting 
     
    27472749        r""" 
    27482750        Return a sequence of the eigenvalues of a matrix, with 
    27492751        multiplicity.  If the eigenvalues are roots of polynomials in 
    2750         CC, then QQbar elements are returned that represent each 
     2752        QQ, then QQbar elements are returned that represent each 
    27512753        separate root. 
    27522754 
    27532755        EXAMPLES: 
     
    27762778            x^4 - 30*x^3 - 171*x^2 + 1460*x + 1784 
    27772779            sage: p(e) == 0 
    27782780            True 
     2781             
     2782        To perform computations on the eigenvalue as an element of a 
     2783        number field, you can always convert back to a number field 
     2784        element. 
    27792785            sage: e.as_number_field_element() 
    27802786            (Number Field in a with defining polynomial y^4 - 2*y^3 - 507*y^2 + 4988*y - 8744, 
    27812787            -a + 8, 
     
    27832789            From: Number Field in a with defining polynomial y^4 - 2*y^3 - 507*y^2 + 4988*y - 8744 
    27842790            To:   Algebraic Real Field 
    27852791            Defn: a |--> 16.35066086057957?) 
    2786  
    27872792        """ 
    27882793        x = self.fetch('eigenvalues') 
    27892794        if not x is None: 
     
    28022807                alpha = [-h[0]/h[1]] 
    28032808            else: 
    28042809                F = h.root_field('%s%s'%('a',i)) 
    2805                 alpha = F.gen(0).galois_conjugates(QQbar) 
     2810                try: 
     2811                    alpha = F.gen(0).galois_conjugates(QQbar) 
     2812                except AttributeError, TypeError: 
     2813                    raise NotImplementedError, "eigenvalues() is not implemented for matrices with eigenvalues that are not in the fraction field of the base ring or in QQbar" 
    28062814            V.extend(alpha*e) 
    28072815            i+=1 
    28082816        V = Sequence(V) 
     
    28532861        evec_list=[] 
    28542862        n = self._nrows 
    28552863        evec_eval_list = [] 
     2864        F = self.base_ring().fraction_field() 
    28562865        for ev in eigenspaces: 
    28572866            eigval = ev[0] 
    28582867            eigbasis = ev[1].basis() 
    28592868            eigmult = ev[2] 
    2860             if hasattr(eigval, 'galois_conjugates'): 
    2861                 eigval_conj = eigval.galois_conjugates(QQbar) 
     2869            if eigval.parent().fraction_field() == F: 
     2870                evec_eval_list.append((eigval, eigbasis, eigmult)) 
     2871            else: 
     2872                try: 
     2873                    eigval_conj = eigval.galois_conjugates(QQbar) 
     2874                except AttributeError, TypeError: 
     2875                    raise NotImplementedError, "eigenvectors are not implemented for matrices with eigenvalues that are not in the fraction field of the base ring or in QQbar" 
     2876                     
    28622877                for e in eigval_conj: 
    28632878                    m = hom(eigval.parent(), e.parent(), e) 
    28642879                    space = (e.parent())**n 
    28652880                    evec_list = [(space)([m(i) for i in v]) for v in eigbasis] 
    28662881                    evec_eval_list.append( (e, evec_list, eigmult)) 
    2867             else: 
    2868                 evec_eval_list.append((eigval, eigbasis, eigmult)) 
     2882 
    28692883        return evec_eval_list 
    28702884 
    28712885    left_eigenvectors = eigenvectors_left 
     
    29052919        r""" 
    29062920        Return matrices D and P, where D is a diagonal matrix of 
    29072921        eigenvalues and P is the corresponding matrix where the rows 
    2908         are corresponding eigenvectors so that P*self = D*P. 
     2922        are corresponding eigenvectors (or zero vectors) so that P*self = D*P. 
    29092923 
    29102924        EXAMPLES: 
    29112925            sage: A = matrix(QQ,3,3,range(9)); A 
     
    29232937            [                   1   1.289897948556636?  1.5797958971132712?] 
    29242938            sage: P*A == D*P 
    29252939            True 
     2940 
     2941        Because P is invertible, A is diagonalizable. 
     2942            sage: A == (~P)*D*P 
     2943            True 
     2944 
     2945        The matrix P may contain zero rows corresponding to 
     2946        eigenvalues for which the algebraic multiplicity is greater 
     2947        than the geometric multiplicity.  In these cases, the matrix 
     2948        is not diagonalizable. 
     2949            sage: A = jordan_block(2,3); A             
     2950            [2 1 0] 
     2951            [0 2 1] 
     2952            [0 0 2] 
     2953            sage: A = jordan_block(2,3) 
     2954            sage: D, P = A.eigenmatrix_left() 
     2955            sage: D 
     2956            [2 0 0] 
     2957            [0 2 0] 
     2958            [0 0 2] 
     2959            sage: P 
     2960            [0 0 1] 
     2961            [0 0 0] 
     2962            [0 0 0] 
     2963            sage: P*A == D*P 
     2964            True 
    29262965        """ 
    29272966        from sage.misc.flatten import flatten 
    29282967        evecs = self.eigenvectors_left() 
     
    29392978        r""" 
    29402979        Return matrices D and P, where D is a diagonal matrix of 
    29412980        eigenvalues and P is the corresponding matrix where the columns 
    2942         are corresponding eigenvectors so that self*P = P*D. 
     2981        are corresponding eigenvectors (or zero vectors) so that self*P = P*D. 
    29432982 
    29442983        EXAMPLES: 
    29452984            sage: A = matrix(QQ,3,3,range(9)); A 
     
    29572996            [                   1 -0.7393876913398137?   5.139387691339814?] 
    29582997            sage: A*P == P*D 
    29592998            True 
     2999 
     3000        Because P is invertible, A is diagonalizable. 
     3001            sage: A == P*D*(~P) 
     3002            True 
     3003             
     3004        The matrix P may contain zero columns corresponding to 
     3005        eigenvalues for which the algebraic multiplicity is greater 
     3006        than the geometric multiplicity.  In these cases, the matrix 
     3007        is not diagonalizable. 
     3008           sage: A = jordan_block(2,3); A     
     3009           [2 1 0] 
     3010           [0 2 1] 
     3011           [0 0 2] 
     3012           sage: A = jordan_block(2,3) 
     3013           sage: D, P = A.eigenmatrix_right() 
     3014           sage: D 
     3015           [2 0 0] 
     3016           [0 2 0] 
     3017           [0 0 2] 
     3018           sage: P 
     3019           [1 0 0] 
     3020           [0 0 0] 
     3021           [0 0 0] 
     3022           sage: A*P == P*D 
     3023           True 
    29603024        """ 
    29613025        D,P=self.transpose().eigenmatrix_left() 
    29623026        return D,P.transpose()