Changeset b24184 in git
- Timestamp:
- Jun 16, 1999, 7:24:35 PM (24 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- e38016b4a56783e188de1f4d208aab897b2f6f25
- Parents:
- 64b0be57e2ca9b4b5ca36cb9e9d11a9e6e2c0eb8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/jordan.lib
r64b0be5 rb24184 1 1 /////////////////////////////////////////////////////////////////////////////// 2 2 3 version="$Id: jordan.lib,v 1.1 0 1999-06-08 09:15:20mschulze Exp $";3 version="$Id: jordan.lib,v 1.11 1999-06-16 17:24:35 mschulze Exp $"; 4 4 info=" 5 5 LIBRARY: jordan.lib PROCEDURES TO COMPUTE THE JORDAN NORMAL FORM … … 15 15 /////////////////////////////////////////////////////////////////////////////// 16 16 17 static proc countblocks(matrix M) 18 { 19 int n; 20 21 int i=1; 22 int r,r0; 23 while(i<=nrows(M)) 24 { 25 n++; 26 r=nrows(M[i]); 27 r0=r; 28 29 while(i<r0&&i<nrows(M)) 30 { 31 i++; 32 if(i<=nrows(M)) 33 { 34 r=nrows(M[i]); 35 if(r>r0) 36 { 37 r0=r; 38 } 39 } 40 } 41 42 i++; 43 } 44 45 return(n); 46 } 47 /////////////////////////////////////////////////////////////////////////////// 48 49 static proc getblock(matrix M,intvec v) 50 { 51 matrix M0[size(v)][size(v)]=M[v,v]; 52 return(M0); 53 } 54 /////////////////////////////////////////////////////////////////////////////// 55 17 56 proc jordan(matrix M,list #) 18 "USAGE: jordan(M[,opt]); with M constant square matrix and opt integer.57 "USAGE: jordan(M[,opt]); M constant square matrix, opt integer 19 58 ASSUME: The eigenvalues of M are in the coefficient field. 20 RETURN: The procedure returns a list lwith 3 entries of type59 RETURN: The procedure returns a list jd with 3 entries of type 21 60 ideal, list of intvecs, matrix with 22 l[1] eigenvalues of M,23 l[2][i][j] size of j-th Jordan block with eigenvalue l[1][i], and24 l[3]^(-1)*M*l[3] in Jordan normal form.25 Depending on opt, only certain entries of lare computed.26 If opt=-1, l[1] is computed,27 if opt= 0, l[1] and l[2] are computed,28 if opt= 1, l[1],l[2], and l[3] are computed, and,29 if opt= 2, l[1] and l[3] are computed.61 jd[1] eigenvalues of M, 62 jd[2][i][j] size of j-th Jordan block with eigenvalue jd[1][i], and 63 jd[3]^(-1)*M*jd[3] in Jordan normal form. 64 Depending on opt, only certain entries of jd are computed. 65 If opt=-1, jd[1] is computed, 66 if opt= 0, jd[1] and jd[2] are computed, 67 if opt= 1, jd[1],jd[2], and jd[3] are computed, and, 68 if opt= 2, jd[1] and jd[3] are computed. 30 69 By default, opt=0. 31 70 NOTE: A non constant polynomial matrix M is replaced by its constant part. … … 33 72 " 34 73 { 35 // test if M is a square matrix74 // check parameter M 36 75 int n=nrows(M); 76 if(n==0) 77 { 78 print("//empty matrix"); 79 return(list()); 80 } 37 81 if(n!=ncols(M)) 38 82 { … … 44 88 M=jet(M,0); 45 89 46 // change to polynomial ring for factorization 47 def br=basering; 48 changeord("pr","dp"); 49 matrix M=imap(br,M); 50 51 // factorize characteristic polynomial of M 52 list l=factorize(det(M-var(1)*freemodule(n)),2); 53 54 // get multiplicities mM of M 55 def eM,mM=l[1..2]; 56 kill l; 57 58 // test if eigenvalues of M are in the coefficient field 59 int i; 60 for(i=size(eM);i>=1;i--) 61 { 62 if(deg(eM[i])>1) 63 { 64 print("//eigenvalues not in the coefficient field"); 65 setring br; 66 kill pr; 67 return(list()); 68 } 69 } 70 71 // get eigenvalues eM of M 72 map inv=pr,-var(1); 73 eM=jet(simplify(inv(eM),1),0); 74 setring br; 75 ideal eM=fetch(pr,eM); 76 kill pr; 77 78 // sort eigenvalues eM 79 int j; 90 // try to increase number of blocks by transposing M 91 if(countblocks(M)<countblocks(transpose(M))) 92 { 93 M=transpose(M); 94 } 95 96 // compute eigenvalues eM and multiplicities mM of M 97 list fac; 98 matrix M0; 99 ideal eM,eM0; 100 intvec mM,mM0; 101 intvec u; 102 int i=1; 103 int j,r,r0; 104 while(i<=nrows(M)) 105 { 106 u=i; 107 r=nrows(M[i]); 108 r0=r; 109 110 // find next block 111 while(i<r0&&i<nrows(M)) 112 { 113 i++; 114 if(i<=nrows(M)) 115 { 116 u=u,i; 117 r=nrows(M[i]); 118 if(r>r0) 119 { 120 r0=r; 121 } 122 } 123 } 124 125 // if 1x1-block 126 if(size(u)==1) 127 { 128 if(mM[1]==0) 129 { 130 eM=M[u[1]][u[1]]; 131 mM=1; 132 } 133 else 134 { 135 eM=eM,ideal(M[u[1]][u[1]]); 136 mM=mM,1; 137 } 138 } 139 else 140 { 141 // factorize characteristic polynomial of block M0 142 M0=getblock(M,u); 143 fac=factorize(det(M0-var(1)*freemodule(size(u))),2); 144 eM0,mM0=fac[1..2]; 145 146 // compute eigenvalues eM0 of M0 147 if(1<var(1)) 148 { 149 for(j=ncols(eM0);j>=1;j--) 150 { 151 if(deg(eM0[j])>1) 152 { 153 print("//eigenvalues not in the coefficient field"); 154 return(list()); 155 } 156 eM0[j]=-(eM0[j][2]/var(1))/eM0[j][1]; 157 } 158 } 159 else 160 { 161 for(j=ncols(eM0);j>=1;j--) 162 { 163 if(deg(eM0[j])>1) 164 { 165 print("//eigenvalues not in the coefficient field"); 166 return(list()); 167 } 168 eM0[j]=-eM0[j][1]/(eM0[j][2]/var(1)); 169 } 170 } 171 172 if(mM[1]==0) 173 { 174 eM=eM0; 175 mM=mM0; 176 } 177 else 178 { 179 eM=eM,eM0; 180 mM=mM,mM0; 181 } 182 } 183 184 i++; 185 } 186 187 // sort eigenvalues 80 188 poly e; 81 189 int m; 82 for(i= size(eM);i>=2;i--)190 for(i=ncols(eM);i>=2;i--) 83 191 { 84 192 for(j=i-1;j>=1;j--) 85 193 { 86 194 if(eM[i]<eM[j]) 87 195 { 88 196 e=eM[i]; … … 95 203 } 96 204 } 97 kill e,m; 205 206 // remove multiple eigenvalues 207 i=1; 208 j=2; 209 while(j<=ncols(eM)) 210 { 211 if(eM[i]==eM[j]) 212 { 213 mM[i]=mM[i]+mM[j]; 214 } 215 else 216 { 217 i++; 218 eM[i]=eM[j]; 219 } 220 j++; 221 } 222 eM=eM[1..i]; 223 mM=mM[1..i]; 98 224 99 225 // get optional parameter opt … … 128 254 } 129 255 130 // do for all eigenvalues eM[i]131 256 for(i=ncols(eM);i>=1;i--) 132 257 { … … 183 308 } 184 309 } 185 kill l; 186 187 // create return list l 188 list l=eM; 310 311 list jd=eM; 189 312 if(opt<=1) 190 313 { 191 l[2]=bM;314 jd[2]=bM; 192 315 } 193 316 if(opt>=1) 194 317 { 195 l[3]=V; 196 } 197 198 return(l); 318 jd[3]=V; 319 } 320 return(jd); 199 321 } 200 322 example … … 207 329 /////////////////////////////////////////////////////////////////////////////// 208 330 209 proc jordanmatrix(list l)210 "USAGE: jordanmatrix( l); with l list of ideal and list of intvecs.211 RETURN: The procedure returns the Jordan matrix J with eigenvalues l[1] and212 size l[2][i][j] of j-th Jordan block with eigenvalue l[1][i].331 proc jordanmatrix(list jd) 332 "USAGE: jordanmatrix(jd); jd list of ideal and list of intvecs 333 RETURN: The procedure returns the Jordan matrix J with eigenvalues jd[1] and 334 size jd[2][i][j] of j-th Jordan block with eigenvalue jd[1][i]. 213 335 EXAMPLE: example jordanmatrix; shows an example. 214 336 " 215 337 { 216 338 // check parameters 217 if(size( l)<2)339 if(size(jd)<2) 218 340 { 219 341 print("//not enough entries in argument list"); … … 221 343 return(J); 222 344 } 223 def eJ,bJ=l[1..2]; 224 kill l; 345 def eJ,bJ=jd[1..2]; 225 346 if(typeof(eJ)!="ideal") 226 347 { … … 302 423 303 424 proc jordanform(matrix M) 304 "USAGE: jordanform(M); with M constant square matrix.425 "USAGE: jordanform(M); M constant square matrix 305 426 ASSUME: The eigenvalues of M are in the coefficient field. 306 427 RETURN: The procedure returns the Jordan normal form of M. … … 321 442 322 443 proc invmat(matrix M) 323 "USAGE: invmat(M); with M constant square matrix.444 "USAGE: invmat(M); M constant square matrix 324 445 ASSUME: M is invertible. 325 446 RETURN: The procedure returns the inverse matrix of M.
Note: See TracChangeset
for help on using the changeset viewer.