Changeset 5dc4ea in git for Singular/LIB/matrix.lib


Ignore:
Timestamp:
Sep 18, 1997, 11:58:26 AM (26 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'e7cc1ebecb61be8b9ca6c18016352af89940b21a')
Children:
1a5daea04547872672e8d5c6d19ac391e34ca05e
Parents:
741512c3f18910d2025325eadcbef56647da00d0
Message:
* hannes: changes to naLcm, naNormalize
* greuel/hannes: changes to deform.lib invar.lib(Header) matrix.lib
     prim_dec.lib primdec.lib


git-svn-id: file:///usr/local/Singular/svn/trunk@730 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/matrix.lib

    r741512c r5dc4ea  
    1 // $Id: matrix.lib,v 1.3 1997-08-12 14:01:08 Singular Exp $
     1// $Id: matrix.lib,v 1.4 1997-09-18 09:58:24 Singular Exp $
    22// (GMG/BM, last modified 22.06.96)
    33///////////////////////////////////////////////////////////////////////////////
     
    1212 is_complex(c);         1 if list c is a complex, 0 if not
    1313 outer(A,B);            matrix, outer product of matrices A and B
     14 power(A,n);            matrix/intmat, n-th power of matrix/intmat A
    1415 skewmat(n[,id]);       generic skew-symmetric nxn matrix [entries from id]
    1516 submat(A,r,c);         submatrix of A with rows/cols specified by intvec r/c
     
    265266////////////////////////////////////////////////////////////////////////////////
    266267
     268proc power ( A, int n)
     269USAGE:   power(A,n);  A a square-matrix of type intmat or matrix, n=integer
     270RETURN:  inmat resp. matrix, the n-th power of A
     271NOTE:    for intamt and big n the result may be wrong because of int overflow
     272EXAMPLE: example power; shows an example
     273{
     274//---------------------------- type checking ----------------------------------
     275   if( typeof(A)!="matrix" and typeof(A)!="intmat" )
     276   {
     277      "// no matrix or intmat!";
     278      return (A);
     279   }
     280   if( ncols(A) != nrows(A) )
     281   {
     282      "// not a suare matrix!";
     283      return();
     284   }
     285//---------------------------- trivial cases ----------------------------------
     286   int ii;
     287   if( n <= 0 )
     288   {
     289      if( typeof(A)=="matrix" )
     290      {
     291         return (unitmat(nrows(A)));
     292      }
     293      if( typeof(A)=="intmat" )
     294      {
     295         intmat B[nrows(A)][nrows(A)];
     296         for( ii=1; ii<=nrows(A); ii++ )
     297         {
     298            B[ii,ii] = 1;
     299         }
     300         return (B);
     301      }
     302   }
     303   if( n == 1 ) { return (A); }
     304//---------------------------- sub procedure ----------------------------------
     305   proc matpow (A, int n)
     306   {
     307      def B = A*A;
     308      int ii= 2;
     309      int jj= 4;
     310      while( jj <= n )
     311      {
     312         B=B*B;
     313         ii=jj;
     314         jj=2*jj;
     315      }
     316      return(B,n-ii);
     317   }
     318//----------------------------- main program ----------------------------------
     319   list L = matpow(A,n);
     320   def B  = L[1];
     321   ii     = L[2];
     322   while( ii>=2 )
     323   {
     324      L = matpow(A,ii);
     325      B = B*L[1];
     326      ii= L[2];
     327   }
     328   if( ii == 0) { return(B); }
     329   if( ii == 1) { return(A*B); }
     330}
     331example
     332{ "EXAMPLE:"; echo = 2;
     333   intmat A[3][3]=1,2,3,4,5,6,7,8,9;
     334   print(power(A,3));"";
     335   ring r=0,(x,y,z),dp;
     336   matrix B[4][4]=0,x,y,z,0,0,y,z,0,0,0,z,x,y,z,0;
     337   print(power(B,3));"";
     338   matrix C[3][3]=1,2,3,4,5,6,7,8,9;
     339   power(C,50);
     340}
     341////////////////////////////////////////////////////////////////////////////////
     342
    267343proc skewmat (int n, list #)
    268344USAGE:   skewmat(n[,id]);  n integer, id ideal
Note: See TracChangeset for help on using the changeset viewer.