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 2448 2448 If algebraic_multiplicity=True, return a list of pairs 2449 2449 (e, V, n) 2450 2450 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. 2454 2455 2455 2456 The eigenspaces are returned sorted by the corresponding characteristic 2456 2457 polynomials, where polynomials are sorted in dictionary order starting … … 2648 2649 If algebraic_multiplicity=True, return a list of pairs 2649 2650 (e, V, n) 2650 2651 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. 2654 2656 2655 2657 The eigenspaces are returned sorted by the corresponding characteristic 2656 2658 polynomials, where polynomials are sorted in dictionary order starting … … 2747 2749 r""" 2748 2750 Return a sequence of the eigenvalues of a matrix, with 2749 2751 multiplicity. If the eigenvalues are roots of polynomials in 2750 CC, then QQbar elements are returned that represent each2752 QQ, then QQbar elements are returned that represent each 2751 2753 separate root. 2752 2754 2753 2755 EXAMPLES: … … 2776 2778 x^4 - 30*x^3 - 171*x^2 + 1460*x + 1784 2777 2779 sage: p(e) == 0 2778 2780 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. 2779 2785 sage: e.as_number_field_element() 2780 2786 (Number Field in a with defining polynomial y^4 - 2*y^3 - 507*y^2 + 4988*y - 8744, 2781 2787 -a + 8, … … 2783 2789 From: Number Field in a with defining polynomial y^4 - 2*y^3 - 507*y^2 + 4988*y - 8744 2784 2790 To: Algebraic Real Field 2785 2791 Defn: a |--> 16.35066086057957?) 2786 2787 2792 """ 2788 2793 x = self.fetch('eigenvalues') 2789 2794 if not x is None: … … 2802 2807 alpha = [-h[0]/h[1]] 2803 2808 else: 2804 2809 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" 2806 2814 V.extend(alpha*e) 2807 2815 i+=1 2808 2816 V = Sequence(V) … … 2853 2861 evec_list=[] 2854 2862 n = self._nrows 2855 2863 evec_eval_list = [] 2864 F = self.base_ring().fraction_field() 2856 2865 for ev in eigenspaces: 2857 2866 eigval = ev[0] 2858 2867 eigbasis = ev[1].basis() 2859 2868 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 2862 2877 for e in eigval_conj: 2863 2878 m = hom(eigval.parent(), e.parent(), e) 2864 2879 space = (e.parent())**n 2865 2880 evec_list = [(space)([m(i) for i in v]) for v in eigbasis] 2866 2881 evec_eval_list.append( (e, evec_list, eigmult)) 2867 else: 2868 evec_eval_list.append((eigval, eigbasis, eigmult)) 2882 2869 2883 return evec_eval_list 2870 2884 2871 2885 left_eigenvectors = eigenvectors_left … … 2905 2919 r""" 2906 2920 Return matrices D and P, where D is a diagonal matrix of 2907 2921 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. 2909 2923 2910 2924 EXAMPLES: 2911 2925 sage: A = matrix(QQ,3,3,range(9)); A … … 2923 2937 [ 1 1.289897948556636? 1.5797958971132712?] 2924 2938 sage: P*A == D*P 2925 2939 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 2926 2965 """ 2927 2966 from sage.misc.flatten import flatten 2928 2967 evecs = self.eigenvectors_left() … … 2939 2978 r""" 2940 2979 Return matrices D and P, where D is a diagonal matrix of 2941 2980 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. 2943 2982 2944 2983 EXAMPLES: 2945 2984 sage: A = matrix(QQ,3,3,range(9)); A … … 2957 2996 [ 1 -0.7393876913398137? 5.139387691339814?] 2958 2997 sage: A*P == P*D 2959 2998 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 2960 3024 """ 2961 3025 D,P=self.transpose().eigenmatrix_left() 2962 3026 return D,P.transpose()