source: git/Singular/LIB/control.lib @ bf42f0

spielwiese
Last change on this file since bf42f0 was bf42f0, checked in by Hans Schoenemann <hannes@…>, 14 years ago
format git-svn-id: file:///usr/local/Singular/svn/trunk@13483 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 43.5 KB
Line 
1version="$Id$";
2category="System and Control Theory";
3info="
4LIBRARY:  control.lib     Algebraic analysis tools for System and Control Theory
5
6AUTHORS:  Oleksandr Iena,       yena@mathematik.uni-kl.de
7@*        Markus Becker,        mbecker@mathematik.uni-kl.de
8@*        Viktor Levandovskyy,  levandov@mathematik.uni-kl.de
9
10SUPPORT: Forschungsschwerpunkt 'Mathematik und Praxis' (Project of Dr. E. Zerz
11and V. Levandovskyy), University of Kaiserslautern
12
13PROCEDURES:
14  control(R);     analysis of controllability-related properties of R (using Ext modules)
15  controlDim(R);  analysis of controllability-related properties of R (using dimension)
16  autonom(R);     analysis of autonomy-related properties of R (using Ext modules)
17  autonomDim(R);  analysis of autonomy-related properties of R (using dimension)
18
19  leftKernel(R);       a left kernel of R
20  rightKernel(R);      a right kernel of R
21  leftInverse(R);      a left inverse of R
22  rightInverse(R);     a right inverse of R
23  colrank(M);          a column rank of M as of matrix
24  genericity(M);       analysis of the genericity of parameters
25  canonize(L);         Groebnerification for modules in the output of control or autonomy procs
26  iostruct(R);         computes an IO-structure of behavior given by a module R
27  findTorsion(R, I);   generators of the submodule of a module R, annihilated by the ideal I
28
29  controlExample(s);   set up an example from the mini database inside of the library
30  view();              well-formatted output of lists, modules and matrices
31";
32
33LIB "homolog.lib";
34LIB "poly.lib";
35LIB "primdec.lib";
36LIB "matrix.lib";
37
38//---------------------------------------------------------------
39static proc Opt_Our()
40"USAGE: Opt_Our();
41RETURN: intvec, where previous options are stored
42PURPOSE: save previous options and set customized options
43"
44{
45  intvec v;
46  v=option(get);
47  option(redSB);
48  option(redTail);
49  return (v);
50}
51
52//-------------------------------------------------------------------------
53
54static proc space(int n)
55"USAGE:spase(n); n is an integer (number of needed spaces)
56RETURN:  string consisting of n spaces
57NOTE:  the procedure is used in the procedure 'view' to have a better formatted output
58"{
59  int i;
60  string s="";
61  for(i=1;i<=n;i++)
62  {
63    s=s+" ";
64  };
65  return(s);
66};
67//-----------------------------------------------------------------------------
68proc view(M)
69"USAGE:  view(M);   M is of any type
70RETURN:  no return value
71PURPOSE:  procedure for (well-) formatted output of modules, matrices, lists of modules, matrices; shows everything even if entries are long
72NOTE:  in case of other types( not 'module', 'matrix', 'list') works just as standard 'print' procedure
73EXAMPLE:  example view; shows an example
74"{
75  // to be replaced with something more feasible
76  if ( (typeof(M)=="module")||(typeof(M)=="matrix") )
77  {
78  int @R=nrows(M);
79  int @C=ncols(M);
80  int i;
81  int j;
82  list MaxLength=list();
83  int Size=0;
84  int max;
85  string s;
86
87  for(i=1;i<=@C;i++)
88  {
89    max=0;
90
91    for(j=1;j<=@R;j++)
92    {
93      Size=size( string( M[j,i] ) );
94      if( Size>max )
95      {
96        max=Size;
97      };
98    };
99    MaxLength[i] = max;
100  };
101
102  for(i=1;i<=@R;i++)
103  {
104    s="";
105    for(j=1;j<@C;j++)
106    {
107      s=s+string(M[i,j])+space( MaxLength[j]-size( string( M[i,j] ) ) ) +",";
108    };
109
110    s=s+string(M[i,j])+space( MaxLength[j]-size( string( M[i,j] ) ) );
111
112    if (i!=@R)
113    {
114      s=s+",";
115    };
116    print(s);
117  };
118
119  return();
120  };
121
122  if(typeof(M)=="list")
123  {
124    int sz=size(M);
125    int i;
126    for(i=1;i<=sz;i++)
127    {
128      view(M[i]);
129      print("");
130    };
131
132    return();
133  };
134  print(M);
135  return();
136}
137example
138{"EXAMPLE:";echo = 2;
139  ring r;
140  list L;
141  matrix M[1][3] = x2+x,y3-y,z5-4z+7;
142  L[1] = "a matrix:";
143  L[2] = M;
144  L[3] = "an ideal:";
145  L[4] = ideal(M);
146  view(L);
147};
148//--------------------------------------------------------------------------
149proc rightKernel(matrix M)
150"USAGE:  rightKernel(M);   M a matrix
151RETURN:  module
152PURPOSE: computes the right kernel of matrix M (a module of all elements v such that Mv=0)
153EXAMPLE: example rightKernel; shows an example
154"{
155  return(modulo(M,std(0)));
156}
157example
158{"EXAMPLE:";echo = 2;
159  ring r = 0,(x,y,z),dp;
160  matrix M[1][3] = x,y,z;
161  print(M);
162  matrix R = rightKernel(M);
163  print(R);
164  // check:
165  print(M*R);
166};
167//-------------------------------------------------------------------------
168proc leftKernel(matrix M)
169"USAGE:  leftKernel(M);   M a matrix
170RETURN:  module
171PURPOSE: computes left kernel of matrix M (a module of all elements v such that vM=0)
172EXAMPLE:  example leftKernel; shows an example
173"
174{
175  return( transpose( modulo( transpose(M),std(0) ) ) );
176}
177example
178{"EXAMPLE:";echo = 2;
179  ring r= 0,(x,y,z),dp;
180  matrix M[3][1] = x,y,z;
181  print(M);
182  matrix L = leftKernel(M);
183  print(L);
184  // check:
185  print(L*M);
186};
187//------------------------------------------------------------------------
188proc leftInverse(module M)
189"USAGE:  leftInverse(M);  M a module
190RETURN:  module
191PURPOSE: computes such a matrix L, that LM = Id;
192EXAMPLE: example leftInverse; shows an example
193NOTE: exists only in the case when M is free submodule
194"
195{
196  // it works also for the NC case;
197  int NCols = ncols(M);
198  module Id = freemodule(NCols);
199  module N  = transpose(M);
200  intvec old_opt=Opt_Our();
201  Id = std(Id);
202  matrix T;
203  // check the correctness (Id \subseteq M)
204  // via dimension: dim (M) = -1!
205  int d = dim_Our(N);
206  if (d != -1)
207  {
208    // No left inverse exists
209    return(matrix(0));
210  }
211  matrix T2 = lift(N, Id);
212  T2 =  transpose(T2);
213  option(set,old_opt);  // set the options back
214  return(T2);
215}
216example
217{
218  "EXAMPLE:";echo =2;
219  // a trivial example:
220  ring r = 0,(x,z),dp;
221  matrix M[2][1] = 1,x2z;
222  print(M);
223  print( leftInverse(M) );
224  kill r;
225  // derived from the example TwoPendula:
226  ring r=(0,m1,m2,M,g,L1,L2),Dt,dp;
227  matrix U[3][1];
228  U[1,1]=(-L2)*Dt^4+(g)*Dt^2;
229  U[2,1]=(-L1)*Dt^4+(g)*Dt^2;
230  U[3,1]=(L1*L2)*Dt^4+(-g*L1-g*L2)*Dt^2+(g^2);
231  module M = module(U);
232  module L = leftInverse(M);
233  print(L);
234  // check
235  print(L*M);
236};
237//-----------------------------------------------------------------------
238proc rightInverse(module R)
239"USAGE:  rightInverse(M);  M a module
240RETURN:  module
241PURPOSE: computes such a matrix L, that ML = Id
242EXAMPLE: example rightInverse; shows an example
243NOTE: exists only in the case when M is free submodule
244"
245{
246  // for comm case it suffices
247  if (isCommutative())
248  {
249    return(transpose(leftInverse(transpose(R))));
250  }
251  // for noncomm
252  def save = basering; def sop = opposite(save);
253  setring sop; module Mop = oppose(save,R);
254  Mop = transpose(Mop);
255  module L = leftInverse(Mop);
256  setring save; module L = oppose(sop,L);
257  L = transpose(L);
258  return(matrix(L));
259}
260example
261{ "EXAMPLE:";echo =2;
262  // a trivial example:
263  ring r = 0,(x,z),dp;
264  matrix M[1][2] = 1,x2+z;
265  print(M);
266  print( rightInverse(M) );
267  kill r;
268  // derived from the TwoPendula example:
269  ring r=(0,m1,m2,M,g,L1,L2),Dt,dp;
270  matrix U[1][3];
271  U[1,1]=(-L2)*Dt^4+(g)*Dt^2;
272  U[1,2]=(-L1)*Dt^4+(g)*Dt^2;
273  U[1,3]=(L1*L2)*Dt^4+(-g*L1-g*L2)*Dt^2+(g^2);
274  module M = module(U);
275  module L = rightInverse(M);
276  print(L);
277  // check
278  print(M*L);
279};
280//-----------------------------------------------------------------------
281static proc dim_Our(module R)
282{
283  int d;
284  if (attrib(R,"isSB")<>1)
285  {
286    R = std(R);
287  }
288  d = dim(R);
289  return(d);
290}
291//-----------------------------------------------------------------------
292static proc Ann_Our(module R)
293{
294  return(Ann(R));
295}
296//-----------------------------------------------------------------------
297static proc Ext_Our(int i, module R, list #)
298{
299  // mimicking 'Ext_R' from homolog.lib
300  int ExtraArg = ( size(#)>0 );
301  if (ExtraArg)
302  {
303    return( Ext_R(i,R,#[1]) );
304  }
305  else
306  {
307    return( Ext_R(i,R) );
308  }
309}
310//------------------------------------------------------------------------
311static proc is_zero_Our
312{
313  //just a copy of 'is_zero' from "poly.lib" patched with GKdim
314  int d = dim_Our(std(#[1]));
315  int a = ( d==-1 );
316  if( size(#) >1 ) { list L=a,d; return(L); }
317  return(a);
318  //  return( is_zero(R) ) ;
319};
320//------------------------------------------------------------------------
321static proc control_output(int i, int NVars, module R, module Ext_1, list Gen)
322"USAGE:  control_output(i, NVars, R, Ext_1),
323PURPOSE: where
324@*         i is integer (number of first nonzero Ext or a number of variables in a basering + 1 in case that all the Exts are zero),
325@*           NVars:  integer, number of variables in a base ring,
326@*           R:  module R (cokernel representation),
327@*           Ext_1:  module, the first Ext(its cokernel representation)
328RETURN:  list with all the contollability properties of the system which is to be returned in 'control' procedure
329NOTE:  this procedure is used in 'control' procedure
330"{
331  // TODO: NVars to be replaced with the global hom. dimension of basering!!!
332  // Is not clear what to do with gl.dim of qrings
333  string DofS = "dimension of the system:";
334  string Fn   = "number of first nonzero Ext:";
335  string Gen_mes = "Parameter constellations which might lead to a non-controllable system:";
336
337  module RK = rightKernel(R);
338  int d=dim_Our(std(transpose(R)));
339
340  if (i==1)
341  {
342    return(
343            list ( Fn,
344                   i,
345                  "not controllable , image representation for controllable part:",
346                    RK,
347                  "kernel representation for controllable part:",
348                   leftKernel( RK ),
349                  "obstruction to controllability",
350                   Ext_1,
351                  "annihilator of torsion module (of obstruction to controllability)",
352                   Ann_Our(Ext_1),
353                   DofS,
354                   d
355                 )
356          );
357  };
358
359  if(i>NVars)
360  {
361    return( list(  Fn,
362                   -1,
363                  "strongly controllable(flat), image representation:",
364                   RK,
365                  "left inverse to image representation:",
366                   leftInverse(RK),
367                   DofS,
368                   d,
369                   Gen_mes,
370                   Gen)
371          );
372  };
373
374  //
375  //now i<=NVars
376  //
377
378  if( (i==2) )
379  {
380    return( list( Fn,
381                  i,
382                 "controllable, not reflexive, image representation:",
383                  RK,
384                  DofS,
385                  d,
386                  Gen_mes,
387                  Gen)
388          );
389  };
390
391  if( (i>=3) )
392  {
393    return( list ( Fn,
394                   i,
395                  "reflexive, not strongly controllable, image representation:",
396                   RK,
397                   DofS,
398                   d,
399                      Gen_mes,
400                   Gen)
401          );
402  };
403};
404//-------------------------------------------------------------------------
405
406proc control(module R)
407"USAGE:  control(R);  R a module (R is the matrix of the system of equations to be investigated)
408RETURN:  list
409PURPOSE: compute the list of all the properties concerning controllability of the system (behavior), represented by the matrix R
410NOTE: the properties and corresponding data like controllability, flatness, dimension of the system, degree of controllability, kernel and image representations, genericity of parameters, obstructions to controllability, annihilator of torsion submodule and left inverse are investigated
411EXAMPLE:  example control; shows an example
412"
413{
414  int i;
415  int NVars=nvars(basering);
416  // TODO: NVars to be replaced with the global hom. dimension of basering!!!
417  int ExtIsZero;
418  intvec v=Opt_Our();
419  module R_std=std(R);
420  module Ext_1 = std(Ext_Our(1,R_std));
421
422  ExtIsZero=is_zero_Our(Ext_1);
423  i=1;
424  while( (ExtIsZero) && (i<=NVars) )
425  {
426    i++;
427    ExtIsZero = is_zero_Our( Ext_Our(i,R_std) );
428  };
429  matrix T=lift(R,R_std);
430  list l=genericity(T);
431  option(set,v);
432
433  return( control_output( i, NVars, R, Ext_1, l ) );
434}
435example
436{"EXAMPLE:";echo = 2;
437  // a WindTunnel example
438  ring A = (0,a, omega, zeta, k),(D1, delta),dp;
439  module R;
440  R = [D1+a, -k*a*delta, 0, 0],
441      [0, D1, -1, 0],
442      [0, omega^2, D1+2*zeta*omega, -omega^2];
443  R=transpose(R);
444  view(R);
445  view(control(R));
446};
447//--------------------------------------------------------------------------
448proc controlDim(module R)
449"USAGE:  controlDim(R); R a module (R is the matrix of the system of equations to be investigated)
450RETURN: list
451PURPOSE: computes list of all the properties concerning controllability of the system (behavior), represented by the  matrix R
452EXAMPLE:  example controlDim; shows an example
453NOTE: the properties and corresponding data like controllability, flatness, dimension of the system, degree of controllability, kernel and image representations, genericity of parameters, obstructions to controllability, annihilator of torsion submodule and left inverse are investigated.
454@* This procedure is analogous to 'control' but uses dimension calculations.
455@* The implemented approach works for full row rank matrices only (the check is done automatically).
456"
457{
458  if( nrows(R) != colrank(transpose(R)) )
459  {
460    return ("controlDim cannot be applied, since R does not have full row rank");
461  }
462  intvec     v = Opt_Our();
463  module R_std = std(R);
464  int        d = dim_Our(R_std);
465  int    NVars = nvars(basering);
466  int        i = NVars-d;
467  module Ext_1 = std(Ext_Our(1,R_std));
468  matrix     T = lift(R,R_std);
469  list       l = genericity(T);
470  option(set, v);
471  return( control_output( i, NVars, R, Ext_1, l));
472}
473example
474{"EXAMPLE:";echo = 2;
475  //a WindTunnel example
476  ring A = (0,a, omega, zeta, k),(D1, delta),dp;
477  module R;
478  R = [D1+a, -k*a*delta, 0, 0],
479      [0, D1, -1, 0],
480      [0, omega^2, D1+2*zeta*omega, -omega^2];
481  R=transpose(R);
482  view(R);
483  view(controlDim(R));
484};
485//------------------------------------------------------------------------
486proc colrank(module M)
487"USAGE: colrank(M); M a matrix/module
488RETURN: int
489PURPOSE: compute the column rank of M as of matrix
490NOTE: this procedure uses Bareiss algorithm
491"{
492  // NOte continued:
493  // which might not terminate in some cases
494  module M_red  = bareiss(M)[1];
495  int NCols_red = ncols(M_red);
496  return (NCols_red);
497}
498example
499{"EXAMPLE: ";echo = 2;
500  // de Rham complex
501  ring r=0,(D(1..3)),dp;
502  module R;
503  R=[0,-D(3),D(2)],
504    [D(3),0,-D(1)],
505    [-D(2),D(1),0];
506  R=transpose(R);
507  colrank(R);
508};
509
510//------------------------------------------------------------------------
511static proc autonom_output( int i, int NVars, module RC, int R_rank )
512"USAGE:  proc autonom_output(i, NVars, RC, R_rank)
513           i:  integer, number of first nonzero Ext or
514               just number of variables in a base ring + 1 in case that all the Exts are zero
515           NVars:  integer, number of variables in a base ring
516           RC: module, kernel-representation of controllable part of the system
517           R_rank: integer, column rank of the representation matrix
518PURPOSE: compute all the autonomy properties of the system which is to be returned in 'autonom' procedure
519RETURN:  list
520NOTE:  this procedure is used in 'autonom' procedure
521"
522{
523  int d=NVars-i;//that is the dimension of the system
524  string DofS="dimension of the system:";
525  string Fn = "number of first nonzero Ext:";
526  if(i==0)
527  {
528    return( list(  Fn,
529                   i,
530                  "not autonomous",
531                   "kernel representation for controllable part",
532                   RC,
533                   "column rank of the matrix",
534                   R_rank,
535                   DofS,
536                   d )
537          );
538  };
539
540  if( i>NVars )
541  {
542    return( list( Fn,
543                  -1,
544                  "trivial",
545                  DofS,
546                  d )
547          );
548  };
549
550  //
551  //now i<=NVars
552  //
553
554
555  if( i==1 )
556  // in case that NVars==1 there is no sense to consider the notion
557  // of strongly autonomous behavior, because it does not imply
558  // that system is overdetermined in this case
559  {
560    return( list ( Fn,
561                   i,
562                  "autonomous, not overdetermined",
563                   DofS,
564                   d )
565          );
566  };
567
568  if( i==NVars )
569  {
570    return( list(  Fn,
571                   i,
572                  "strongly autonomous(fin. dimensional),in particular overdetermined",
573                   DofS,
574                   d)
575          );
576  };
577
578  if( i<NVars )
579  {
580    return( list ( Fn,
581                   i,
582                  "overdetermined, not strongly autonomous",
583                   DofS,
584                   d)
585          );
586  };
587};
588//--------------------------------------------------------------------------
589proc autonomDim(module R)
590"USAGE:  autonomDim(R);   R a module (R is a matrix of the system of equations which is to be investigated)
591RETURN: list
592PURPOSE: computes the list of all the properties concerning autonomy of the system (behavior), represented by the matrix R
593NOTE: the properties and corresponding data like autonomy resp. strong autonomy, dimension of the system, autonomy degree, kernel representation and (over)determinacy are investigated.
594@* This procedure is analogous to 'autonom' but uses dimension calculations
595EXAMPLE:  example autonomDim; shows an example
596"
597{
598  int d;
599  int NVars  = nvars(basering);
600  module RT  = transpose(R);
601  module RC;  //for computation of controllable part if if exists
602  int R_rank = ncols(R);
603  d          = dim_Our( std(RT) );  //this is the dimension of the system
604  int      i = NVars-d;  //First non-zero Ext
605  if( d==0 )
606    {
607      RC = leftKernel(rightKernel(R));
608      R_rank=colrank(R);
609    }
610  return( autonom_output(i,NVars,RC,R_rank) );
611}
612example
613{"EXAMPLE:"; echo = 2;
614  // Cauchy1 example
615  ring r=0,(s1,s2,s3,s4),dp;
616  module R= [s1,-s2],
617            [s2, s1],
618            [s3,-s4],
619            [s4, s3];
620  R=transpose(R);
621  view( R );
622  view( autonomDim(R) );
623};
624//----------------------------------------------------------
625proc autonom(module R)
626"USAGE:  autonom(R);   R a module (R is a matrix of the system of equations which is to be investigated)
627RETURN:  list
628PURPOSE: find all the properties concerning autonomy of the system (behavior) represented by the  matrix R
629NOTE: the properties and corresponding data like autonomy resp. strong autonomy, dimension of the system, autonomy degree, kernel representation and (over)determinacy are investigated
630EXAMPLE: example autonom; shows an example
631"
632{
633  int NVars=nvars(basering);
634  int ExtIsZero;
635  module RT=transpose(R);
636  module RC;
637  int R_rank=ncols(R);
638  ExtIsZero=is_zero_Our(Ext_Our(0,RT));
639  int i=0;
640  while( (ExtIsZero)&&(i<=NVars) )
641  {
642    i++;
643    ExtIsZero = is_zero_Our(Ext_Our(i,RT));
644  };
645  if (i==0)
646  {
647    RC = leftKernel(rightKernel(R));
648    R_rank=colrank(R);
649  }
650  return(autonom_output(i,NVars,RC,R_rank));
651}
652example
653{"EXAMPLE:"; echo = 2;
654  // Cauchy
655  ring r=0,(s1,s2,s3,s4),dp;
656  module R= [s1,-s2],
657            [s2, s1],
658            [s3,-s4],
659            [s4, s3];
660  R=transpose(R);
661  view( R );
662  view( autonom(R) );
663};
664
665
666//----------------------------------------------------------
667proc genericity(matrix M)
668"USAGE:  genericity(M); M is a matrix/module
669RETURN:  list (of strings)
670PURPOSE: determine parametric expressions which have been assumed to be non-zero in the process of computing the Groebner basis
671NOTE: the output list consists of strings. The first string contains the variables only, whereas each further string contains
672      a single polynomial in parameters.
673@* We strongly recommend to switch on the redSB and redTail options.
674@* The procedure is effective with the lift procedure for modules with parameters
675EXAMPLE:  example genericity; shows an example
676"
677{
678  // returns "-", if there are no parameters!
679  if (npars(basering)==0)
680  {
681    return("-");
682  }
683  list RT = evas_genericity(M); // list of strings
684  if ((size(RT)==1) && (RT[1] == ""))
685  {
686    return("-");
687  }
688  return(RT);
689}
690example
691{  // TwoPendula
692  "EXAMPLE:"; echo = 2;
693  ring r=(0,m1,m2,M,g,L1,L2),Dt,dp;
694  module RR =
695    [m1*L1*Dt^2, m2*L2*Dt^2, -1, (M+m1+m2)*Dt^2],
696    [m1*L1^2*Dt^2-m1*L1*g, 0, 0, m1*L1*Dt^2],
697    [0, m2*L2^2*Dt^2-m2*L2*g, 0, m2*L2*Dt^2];
698  module R = transpose(RR);
699  module SR = std(R);
700  matrix T = lift(R,SR);
701  genericity(T);
702  //-- The result might be different when computing reduced bases:
703  matrix T2;
704  option(redSB);
705  option(redTail);
706  module SR2 = std(R);
707  T2 =  lift(R,SR2);
708  genericity(T2);
709}
710//---------------------------------------------------------------
711static proc victors_genericity(matrix M)
712{
713  // returns "-", if there are no parameters!
714  if (npars(basering)==0)
715  {
716    return("-");
717  }
718  int plevel = printlevel-voice+2;
719  // M is a matrix over a ring with params and vars;
720  ideal I = ideal(M); // a list of entries
721  I = simplify(I,2); // delete 0's
722  // decompose every coeff in every poly
723  int i;
724  int s = size(I);
725  ideal NM;
726  poly p;
727  number num;
728  int  cl=1;
729  intvec ZeroVec; ZeroVec[nvars(basering)] = 0;
730  intvec W;
731  ideal Numero, Denomiro;
732  int cNu=0; int cDe=0;
733  for (i=1; i<=s; i++)
734  {
735    // remove contents and add them as polys
736    p   = I[i];
737    W   = leadexp(p);
738    if (W == ZeroVec) // i.e. just a coef
739    {
740      num    = denominator(leadcoef(p)); // from poly.lib
741      NM[cl] = numerator(leadcoef(p));
742      dbprint(p,"numerator:");
743      dbprint(p, string(NM[cl]));
744      cNu++; Numero[cNu]= NM[cl];
745      cl++;
746      NM[cl] = num; // denominator
747      dbprint(p,"denominator:");
748      dbprint(p, string(NM[cl]));
749      cDe++; Denomiro[cDe]= NM[cl];
750      cl++;
751      p = p - lead(p); // for the next cycle
752    }
753    if ( p!= 0)
754    {
755      num = content(p);
756      p   = p/num;
757      NM[cl] = denominator(num);
758      dbprint(p,"content denominator:");
759      dbprint(p, string(NM[cl]));
760      cNu++; Numero[cNu]= NM[cl];
761      cl++;
762      NM[cl] = numerator(num);
763      dbprint(p,"content numerator:");
764      dbprint(p, string(NM[cl]));
765      cDe++; Denomiro[cDe]= NM[cl];
766      cl++;
767    }
768    // it seems that the next elements will not have real influence
769    while( p != 0)
770    {
771      NM[cl] = leadcoef(p); // should be all integer, i.e. non-rational
772      dbprint(p,"coef:");
773      dbprint(p, string(NM[cl]));
774      cl++;
775      p = p - lead(p);
776    }
777  }
778  NM = simplify(NM,4); // delete identical
779  string newvars = parstr(basering);
780  def save = basering;
781  string NewRing = "ring @NR =" +string(char(basering))+",("+newvars+"),Dp;";
782  execute(NewRing);
783  // get params as variables
784  // create a list of non-monomials
785  ideal @L;
786  ideal F;
787  ideal NM = imap(save,NM);
788  NM = simplify(NM,8); //delete multiples
789  poly p,q;
790  cl = 1;
791  int j, cf;
792  for(i=1; i<=size(NM);i++)
793  {
794    p = NM[i] - lead(NM[i]);
795    if (p!=0)
796    {
797      //      L[cl] = p;
798      F  = factorize(NM[i],1); //non-constant factors only
799      cf = 1;
800      // factorize every polynomial
801      // throw away every monomial from factorization (also constants from above ring)
802      for (j=1; j<=size(F);j++)
803      {
804        q = F[j]-lead(F[j]);
805        if (q!=0)
806        {
807          @L[cl] = F[j];
808          cl++;
809        }
810      }
811    }
812  }
813  // return the result [in string-format]
814  @L = simplify(@L,2+4+8); // skip zeroes, doubled and entries, diff. by a constant
815  list SL;
816  for (j=1; j<=size(@L);j++)
817  {
818    SL[j] = string(@L[j]);
819  }
820  setring save;
821  return(SL);
822}
823//---------------------------------------------------------------
824static proc evas_genericity(matrix M)
825{
826  // called from the main genericity proc
827  ideal I = ideal(M);
828  I = simplify(I,2+4);
829  int s = ncols(I);
830  ideal Den;
831  poly p;
832  int i;
833  for (i=1; i<=s; i++)
834  {
835    p = I[i];
836    while (p !=0)
837    {
838      Den = Den, denominator(leadcoef(p));
839      p   = p-lead(p);
840    }
841  }
842  Den = simplify(Den,2+4);
843  string newvars = parstr(basering);
844  def save = basering;
845  string NewRing = "ring @NR =(" +string(char(basering))+"),("+newvars+"),Dp;";
846  execute(NewRing);
847  ideal F;
848  ideal Den = imap(save,Den);
849  Den = simplify(Den,2);
850  int s1 = ncols(Den);
851  for (i=1; i<=s1; i++)
852  {
853    Den[i] = normalize(Den[i]);
854    if ( Den[i] !=1)
855    {
856      F= F, factorize(Den[i],1);
857    }
858  }
859  F = simplify(F, 2+4+8);
860  ideal @L = F;
861  @L = simplify(@L,2);
862  list SL;
863  int c,j;
864  string Mono;
865  c = 1;
866  for (j=1; j<= ncols(@L);j++)
867  {
868    if (leadcoef(@L[j]) <0)
869    {
870      @L[j] = -1*@L[j];
871    }
872    if (((@L[j] - lead(@L[j]))==0 ) && (@L[j]!=0) ) //@L[j] is a monomial
873    {
874      Mono = Mono + string(@L[j])+ ","; // concatenation
875    }
876    else
877    {
878      c++;
879      SL[c] = string(@L[j]);
880    }
881  }
882  if (Mono!="")
883  {
884    Mono = Mono[1..size(Mono)-1]; // delete the last colon
885  }
886  SL[1] = Mono;
887  setring save;
888  return(SL);
889}
890
891//---------------------------------------------------------------
892proc canonize(list L)
893"USAGE:  canonize(L); L a list
894RETURN:  list
895PURPOSE: modules in the list are canonized by computing their reduced minimal (= unique up to constant factor w.r.t. the given ordering) Groebner bases
896ASSUME:  L is the output of control/autonomy procedures
897EXAMPLE:  example canonize; shows an example
898"
899{
900  list M = L;
901  intvec v=Opt_Our();
902  int s = size(L);
903  int i;
904  for (i=2; i<=s; i=i+2)
905  {
906    if (typeof(M[i])=="module")
907    {
908      M[i] = std(M[i]);
909      //      M[i] = prune(M[i]); // mimimal embedding: no need yet
910      //      M[i] = std(M[i]);
911    }
912  }
913  option(set, v); //set old values back
914  return(M);
915}
916example
917{  // TwoPendula with L1=L2=L
918  "EXAMPLE:"; echo = 2;
919  ring r=(0,m1,m2,M,g,L),Dt,dp;
920  module RR =
921    [m1*L*Dt^2, m2*L*Dt^2, -1, (M+m1+m2)*Dt^2],
922    [m1*L^2*Dt^2-m1*L*g, 0, 0, m1*L*Dt^2],
923    [0, m2*L^2*Dt^2-m2*L*g, 0, m2*L*Dt^2];
924  module R = transpose(RR);
925  list C = control(R);
926  list CC = canonize(C);
927  view(CC);
928}
929
930//----------------------------------------------------------------
931
932static proc elementof (int i, intvec v)
933{
934  int b=0;
935  for(int j=1;j<=nrows(v);j++)
936    {
937      if(v[j]==i)
938        {
939          b=1;
940          return (b);
941        }
942    }
943  return (b);
944}
945//-----------------------------------------------------------------
946proc iostruct(module R)
947"USAGE: iostruct( R ); R a module
948RETURN:  list L with entries: string s, intvec v, module P and module Q
949PURPOSE:  if R is the kernel-representation-matrix of some system, then we output a input-ouput representation Py=Qu of the system, the components that have been chosen as outputs(intvec v) and a comment s
950NOTE:  the procedure uses Bareiss algorithm
951EXAMPLE:  example iostruct; shows an example
952"
953{
954  // NOTE cont'd
955  //which might not terminate in some cases
956  list L = bareiss(R);
957  int R_rank = ncols(L[1]);
958  int NCols=ncols(R);
959  intvec v=L[2];
960  int temp;
961  int NRows=nrows(v);
962  int i,j;
963  int b=1;
964  module P;
965  module Q;
966  int n=0;
967
968  while(b==1)               //sort v through bubblesort
969    {
970      b=0;
971      for(i=1;i<NRows;i++)
972        {
973          if(v[i]>v[i+1])
974          {
975            temp=v[i];
976            v[i]=v[i+1];
977            v[i+1]=temp;
978            b=1;
979          }
980        }
981    }
982  P=R[v];                     //generate P
983  for(i=1;i<=NCols;i++)       //generate Q
984    {
985      if(elementof(i,v)==1)
986        {
987          i++;
988          continue;
989        }
990      Q=Q,R[i];
991    }
992  Q=simplify(Q,2);
993  string s="The following components have been chosen as outputs: ";
994  return (list(s,v,P,Q));
995}
996example
997{"EXAMPLE:";echo = 2;
998 //Example Antenna
999 ring r = (0, K1, K2, Te, Kp, Kc),(Dt, delta), (c,dp);
1000 module RR;
1001 RR =
1002   [Dt, -K1, 0, 0, 0, 0, 0, 0, 0],
1003   [0, Dt+K2/Te, 0, 0, 0, 0, -Kp/Te*delta, -Kc/Te*delta, -Kc/Te*delta],
1004   [0, 0, Dt, -K1, 0, 0, 0, 0, 0],
1005   [0, 0, 0, Dt+K2/Te, 0, 0, -Kc/Te*delta, -Kp/Te*delta, -Kc/Te*delta],
1006   [0, 0, 0, 0, Dt, -K1, 0, 0, 0],
1007   [0, 0, 0, 0, 0, Dt+K2/Te, -Kc/Te*delta, -Kc/Te*delta, -Kp/Te*delta];
1008 module R = transpose(RR);
1009 view(iostruct(R));
1010};
1011
1012//---------------------------------------------------------------
1013static proc smdeg(matrix N)
1014"USAGE: smdeg( N ); N a matrix
1015RETURN:  intvec
1016PURPOSE: returns an intvec of length 2 with the index of an element of N with smallest degree
1017"
1018{
1019  int n = nrows(N);
1020  int m = ncols(N);
1021  int d,d_temp;
1022  intvec v;
1023  int i,j;            // counter
1024
1025  if (N==0)
1026  {
1027    v = 1,1;
1028    return(v);
1029  }
1030
1031  for (i=1; i<=n; i++)
1032// hier wird ein Element ausgewaehlt(!=0) und mit dessen Grad gestartet
1033  {
1034    for (j=1; j<=m; j++)
1035    {
1036      if( deg(N[i,j])!=-1 )
1037      {
1038        d=deg(N[i,j]);
1039        break;
1040      }
1041    }
1042    if (d != -1)
1043    {
1044      break;
1045    }
1046  }
1047  for(i=1; i<=n; i++)
1048  {
1049    for(j=1; j<=m; j++)
1050    {
1051      d_temp = deg(N[i,j]);
1052      if ( (d_temp < d) && (N[i,j]!=0) )
1053      {
1054        d=d_temp;
1055      }
1056    }
1057  }
1058  for (i=1; i<=n; i++)
1059  {
1060    for (j=1; j<=m;j++)
1061    {
1062      if ( (deg(N[i,j]) == d) && (N[i,j]!=0) )
1063      {
1064        v = i,j;
1065        return(v);
1066      }
1067    }
1068  }
1069}
1070//---------------------------------------------------------------
1071static proc NoNon0Pol(vector v)
1072"USAGE: NoNon0Pol(v), v a vector
1073RETURN:  int
1074PURPOSE: returns 1, if there is only one non-zero element in v and 0 else
1075"{
1076  int i,j;
1077  int n = nrows(v);
1078  for( j=1; j<=n; j++)
1079  {
1080    if (v[j] != 0)
1081    {
1082      i++;
1083    }
1084  }
1085  if ( i!=1 )
1086  {
1087    i=0;
1088  }
1089  return(i);
1090}
1091//---------------------------------------------------------------
1092static proc extgcd_Our(poly p, poly q)
1093{
1094  ideal J;   //for extgcd-computations
1095  matrix T; //----------"------------
1096  list L;
1097  // the extgcd-command has a bug in versions before 2-0-7
1098  if ( system("version")<=2006 )
1099  {
1100    J = p,q; // J = N[k-1,k-1],N[k,k]; //J is of type ideal
1101    L[1] = liftstd(J,T);  //T is of type matrix
1102    if(J[1]==p) //this is just for the case the SINGULAR swaps the
1103    //      two elements due to ordering
1104    {
1105      L[2] = T[1,1];
1106      L[3] = T[2,1];
1107    }
1108    else
1109    {
1110      L[2] = T[2,1];
1111      L[3] = T[1,1];
1112    }
1113  }
1114  else
1115  {
1116    L=extgcd(p,q);
1117    //    L=extgcd(N[k-1,k-1],N[k,k]);
1118    //one can use this line if extgcd-bug is fixed
1119  }
1120  return(L);
1121}
1122static proc normalize_Our(matrix N, matrix Q)
1123"USAGE: normalize_Our(N,Q), N, Q are two matrices
1124PURPOSE: normalizes N and divides the columns of Q through the leading coefficients of the columns of N
1125RETURN: normalized matrix N and altered Q(according to the scheme mentioned in purpose). If number of columns of N and Q do not coincide, N and Q are returned unchanged
1126NOTE: number of columns of N and Q must coincide.
1127"
1128{
1129  if(ncols(N) != ncols(Q))
1130    {
1131      return (N,Q);
1132    }
1133  module M = module(N);
1134  module S = module(Q);
1135  int NCols = ncols(N);
1136  number n;
1137  for(int i=1;i<=NCols;i++)
1138    {
1139      n = leadcoef(M[i]);
1140      if( n != 0 )
1141        {
1142          M[i]=M[i]/n;
1143          S[i]=S[i]/n;
1144        }
1145     }
1146   N = matrix(M);
1147   Q = matrix(S);
1148   return (N,Q);
1149}
1150
1151//---------------------------------------------------------------
1152proc oldsmith( module M )
1153"USAGE: oldsmith(M); M a module/matrix
1154PURPOSE: computes the Smith normal form of a matrix
1155RETURN: a list of length 4 with the following entries:
1156@*      [1]: the Smith normal form S of M,
1157@*      [2]: the rank of M,
1158@*      [3]: a unimodular matrix U,
1159@*      [4]: a unimodular matrix V,
1160such that U*M*V=S. An warning is returned when no Smith form exists.
1161NOTE: Older experimental implementation. The Smith form only exists over PIDs (principal ideal domains). Use global ordering for computations!
1162"
1163{
1164  if (nvars(basering)>1) //if more than one variable, return empty list
1165  {
1166    string s="The Smith-Form only exists for principal ideal domains";
1167    return (s);
1168  }
1169  matrix N = matrix(M);         //Typecasting
1170  int n = nrows(N);
1171  int m = ncols(N);
1172  matrix P = unitmat(n);       //left transformation matrix
1173  matrix Q = unitmat(m);       //right transformation matrix
1174  int k, i, j, deg_temp;
1175  poly tmp;
1176  vector v;
1177  list L;                      //for extgcd-computation
1178  intmat f[1][n];              //to save degrees
1179  matrix lambda[1][n];         //to save leadcoefficients
1180  intmat g[1][m];              //to save degrees
1181  matrix mu[1][m];             //to save leadcoefficients
1182  int ii;                       //counter
1183
1184  while ((k!=n) && (k!=m) )
1185  {
1186    k++;
1187    while ((k<=n) && (k<=m))  //outer while-loop for column-operations
1188    {
1189      while(k<=m )        //inner while-loop for row-operations
1190      {
1191        if( (n>m) && (k < n) && (k<m))
1192        {
1193          if( simplify((ideal(submat(N,k+1..n,k+1..m))),2)== 0)
1194          {
1195            return(N,k-1,P,Q);
1196          }
1197        }
1198        i,j = smdeg(submat(N,k..n,k..m)); //choose smallest degree in the remaining submatrix
1199        i=i+(k-1);                        //indices adjusted to the whole matrix
1200        j=j+(k-1);
1201        if(i!=k)                    //take the element with smallest degree in the first position
1202        {
1203          N=permrow(N,i,k);
1204          P=permrow(P,i,k);
1205        }
1206        if(j!=k)
1207        {
1208          N=permcol(N,j,k);
1209          Q=permcol(Q,j,k);
1210        }
1211        if(NoNon0Pol(N[k])==1)
1212        {
1213          break;
1214        }
1215        tmp=leadcoef(N[k,k]);
1216        deg_temp=ord(N[k,k]);             //ord outputs the leading degree of N[k,k]
1217        for(ii=k+1;ii<=n;ii++)
1218        {
1219          lambda[1,ii]=leadcoef(N[ii,k])/tmp;
1220          f[1,ii]=deg(N[ii,k])-deg_temp;
1221        }
1222        for(ii=k+1;ii<=n;ii++)
1223        {
1224          N = addrow(N,k,-lambda[1,ii]*var(1)^f[1,ii],ii);
1225          P = addrow(P,k,-lambda[1,ii]*var(1)^f[1,ii],ii);
1226          N,Q=normalize_Our(N,Q);
1227        }
1228      }
1229      if (k>n)
1230      {
1231        break;
1232      }
1233      if(NoNon0Pol(transpose(N)[k])==1)
1234      {
1235        break;
1236      }
1237      tmp=leadcoef(N[k,k]);
1238      deg_temp=ord(N[k,k]); //ord outputs the leading degree of N[k][k]
1239
1240      for(ii=k+1;ii<=m;ii++)
1241      {
1242        mu[1,ii]=leadcoef(N[k,ii])/tmp;
1243        g[1,ii]=deg(N[k,ii])-deg_temp;
1244      }
1245      for(ii=k+1;ii<=m;ii++)
1246      {
1247        N=addcol(N,k,-mu[1,ii]*var(1)^g[1,ii],ii);
1248        Q=addcol(Q,k,-mu[1,ii]*var(1)^g[1,ii],ii);
1249        N,Q=normalize_Our(N,Q);
1250      }
1251    }
1252    if( (k!=1) && (k<n) && (k<m) )
1253    {
1254      L = extgcd_Our(N[k-1,k-1],N[k,k]);
1255      if ( N[k-1,k-1]!=L[1] )  //means that N[k-1,k-1] is not a divisor of N[k,k]
1256      {
1257        N=addrow(N,k-1,L[2],k);
1258        P=addrow(P,k-1,L[2],k);
1259        N,Q=normalize_Our(N,Q);
1260
1261        N=addcol(N,k,-L[3],k-1);
1262        Q=addcol(Q,k,-L[3],k-1);
1263        N,Q=normalize_Our(N,Q);
1264        k=k-2;
1265      }
1266    }
1267  }
1268  if( (k<=n) && (k<=m) )
1269  {
1270    if( N[k,k]==0)
1271    {
1272      return(N,k-1,P,Q);
1273    }
1274  }
1275  return(N,k,P,Q);
1276}
1277example
1278{
1279  "EXAMPLE:";echo = 2;
1280  option(redSB);
1281  option(redTail);
1282  ring r   = 0,x,dp;
1283  module M = [x2,x,3x3-4], [2x2-1,4x,5x2], [2x5,3x,4x];
1284  print(M);
1285  list P = oldsmith(M);
1286  print(P[1]);
1287  matrix N = matrix(M);
1288  matrix B = P[3]*N*P[4];
1289  print(B);
1290}
1291// see what happens when the matrix is already in Smith-Form
1292//  module M = [x,0,0],[0,x2,0],[0,0,x3];
1293//  list L = oldsmith(M);
1294// print(L[1]);
1295//matrix N=matrix(M);
1296//matrix B=L[3]*N*L[4];
1297//print(B);
1298//---------------------------------------------------------------
1299static proc list_tex(L, string name,link l,int nr_loop)
1300"USAGE: list_tex(L,name,l), where L is a list, name a string, l a link
1301         writes the content of list L in a tex-file 'name'
1302RETURN: nothing
1303"
1304{
1305  if(typeof(L)!="list")  //in case L is not a list
1306  {
1307    texobj(name,L);
1308  }
1309  if(size(L)==0)
1310  {
1311  }
1312  else
1313  {
1314    string t;
1315    for (int i=1;i<=size(L);i++)
1316    {
1317      while(1)
1318      {
1319        if(typeof(L[i])=="string")  //Fehler hier fuer normalen output->nur wenn string in liste dann verbatim
1320        {
1321          t=L[i];
1322          if(nr_loop==1)
1323          {
1324            write(l,"\\begin\{center\}");
1325            write(l,"\\begin\{verbatim\}");
1326          }
1327          write(l,t);
1328          if(nr_loop==0)
1329          {
1330            write(l,"\\par");
1331          }
1332          if(nr_loop==1)
1333          {
1334            write(l,"\\end\{verbatim\}");
1335            write(l,"\\end\{center\}");
1336          }
1337          break;
1338        }
1339        if(typeof(L[i])=="module")
1340        {
1341          texobj(name,matrix(L[i]));
1342          break;
1343        }
1344        if(typeof(L[i])=="list")
1345        {
1346          list_tex(L[i],name,l,1);
1347          break;
1348        }
1349        write(l,"\\begin\{center\}");
1350        texobj(name,L[i]);
1351        write(l,"\\end\{center\}");
1352        write(l,"\\par");
1353        break;
1354      }
1355    }
1356  }
1357}
1358example
1359{
1360  "EXAMPLE:";echo = 2;
1361}
1362//---------------------------------------------------------------
1363proc verbatim_tex(string s, link l)
1364"USAGE: verbatim_tex(s,l), where s is a string and l a link
1365PURPOSE: writes the content of s in verbatim-environment in the file
1366         specified by link
1367RETURN: nothing
1368"
1369{
1370  write(l,"\\begin{verbatim}");
1371  write(l,s);
1372  write(l,"\\end{verbatim}");
1373  write(l,"\\par");
1374}
1375example
1376{
1377  "EXAMPLE:";echo = 2;
1378}
1379//---------------------------------------------------------------
1380proc findTorsion(module R, ideal TAnn)
1381"USAGE:  findTorsion(R, I);   R an ideal/matrix/module, I an ideal
1382RETURN:  module
1383PURPOSE: computes the Groebner basis of the submodule of R, annihilated by I
1384NOTE: especially helpful, when I is the annihilator of the t(R) - the torsion submodule of R. In this case, the result is the explicit presentation of t(R) as
1385the submodule of R
1386EXAMPLE: example findTorsion; shows an example
1387"
1388{
1389  // motivation: let R be a module,
1390  // TAnn is the annihilator of t(R)\subset R
1391  // compute the generators of t(R) explicitly
1392  ideal AS = TAnn;
1393  module S = R;
1394  if (attrib(S,"isSB")<>1)
1395  {
1396    S = std(S);
1397  }
1398  if (attrib(AS,"isSB")<>1)
1399  {
1400    AS = std(AS);
1401  }
1402  int nc  = ncols(S);
1403  module To = quotient(S,AS);
1404  To = std(NF(To,S));
1405  return(To);
1406}
1407example
1408{
1409  "EXAMPLE:";echo = 2;
1410  // Flexible Rod
1411  ring A = 0,(D1, D2), (c,dp);
1412  module R= [D1, -D1*D2, -1], [2*D1*D2, -D1-D1*D2^2, 0];
1413  module RR = transpose(R);
1414  list L = control(RR);
1415  // here, we have the annihilator:
1416  ideal LAnn = D1; // = L[10]
1417  module Tr  = findTorsion(RR,LAnn);
1418  print(RR);  // the module itself
1419  print(Tr); // generators of the torsion submodule
1420}
1421
1422
1423proc controlExample(string s)
1424"USAGE:  controlExample(s);   s a string
1425RETURN:  ring
1426PURPOSE: set up an example from the mini database by initalizing a ring and a module in a ring
1427NOTE: in order to see the list of available examples, execute @code{controlExample(\"show\");}
1428@* To use an example, one has to do the following. Suppose one calls the ring, where the example will be activated, A. Then, by executing
1429@*  @code{def A = controlExample(\"Antenna\");} and @code{setring A;},
1430@* A will become a basering from the example \"Antenna\" with
1431the predefined system module R (transposed).
1432After that one can just execute @code{control(R);} respectively
1433@code{autonom(R);} to perform the control resp. autonomy analysis of R.
1434EXAMPLE: example controlExample; shows an example
1435"{
1436  list E, S, D; // E=official name, S=synonym, D=description
1437  E[1] = "Cauchy1";  S[1] = "cauchy1";  D[1] = "1-dimensional Cauchy equation";
1438  E[2] = "Cauchy2";  S[2] = "cauchy2";  D[2] = "2-dimensional Cauchy equation";
1439  E[3] = "Control1"; S[3] = "control1"; D[3] = "example of a simple noncontrollable system";
1440  E[4] = "Control2"; S[4] = "control2"; D[4] = "example of a simple controllable system";
1441  E[5] = "Antenna";  S[5] = "antenna";  D[5] = "antenna";
1442  E[6] = "Einstein"; S[6] = "einstein"; D[6] = "Einstein equations in vacuum";
1443  E[7] = "FlexibleRod"; S[7] = "flexible rod"; D[7] = "flexible rod";
1444  E[8] = "TwoPendula";  S[8] = "two pendula";  D[8] = "two pendula mounted on a cart";
1445  E[9] = "WindTunnel";  S[9] = "wind tunnel";D[9] = "wind tunnel";
1446  E[10] = "Zerz1";      S[10] = "zerz1"; D[10] = "example from the lecture of Eva Zerz";
1447  // all the examples so far
1448  int i;
1449  if ( (s=="show") || (s=="Show") )
1450  {
1451    print("The list of examples:");
1452    for (i=1; i<=size(E); i++)
1453    {
1454      printf("name: %s,  desc: %s", E[i],D[i]);
1455    }
1456    return();
1457  }
1458  string t;
1459  for (i=1; i<=size(E); i++)
1460  {
1461    if ( (s==E[i]) || (s==S[i]) )
1462    {
1463      t = "def @A = ex"+E[i]+"();";
1464      execute(t);
1465      return(@A);
1466    }
1467  }
1468  "No example found";
1469  return();
1470}
1471example
1472{
1473  "EXAMPLE:";echo = 2;
1474  controlExample("show");   // let us see all available examples:
1475  def B = controlExample("TwoPendula"); // let us set up a particular example
1476  setring B;
1477  print(R);
1478}
1479
1480//----------------------------------------------------------
1481//
1482//Some example rings with defined systems
1483//----------------------------------------------------------
1484//autonomy:
1485//
1486//----------------------------------------------------------
1487static proc exCauchy1()
1488{
1489  ring @r=0,(s1,s2),dp;
1490  module R= [s1,-s2],
1491            [s2, s1];
1492  R=transpose(R);
1493  export R;
1494  return(@r);
1495}
1496//----------------------------------------------------------
1497static proc exCauchy2()
1498{
1499  ring @r=0,(s1,s2,s3,s4),dp;
1500  module R= [s1,-s2],
1501            [s2, s1],
1502            [s3,-s4],
1503            [s4, s3];
1504  R=transpose(R);
1505  export R;
1506  return(@r);
1507}
1508//----------------------------------------------------------
1509static proc exZerz1()
1510{
1511  ring @r=0,(d1,d2),dp;
1512  module R=[d1^2-d2],
1513           [d2^2-1];
1514  R=transpose(R);
1515  export R;
1516  return(@r);
1517}
1518//----------------------------------------------------------
1519//control
1520//----------------------------------------------------------
1521static proc exControl1()
1522{
1523  ring @r=0,(s1,s2,s3),dp;
1524  module R=[0,-s3,s2],
1525           [s3,0,-s1];
1526  R=transpose(R);
1527  export R;
1528  return(@r);
1529}
1530//----------------------------------------------------------
1531static proc exControl2()
1532{
1533  ring @r=0,(s1,s2,s3),dp;
1534  module R=[0,-s3,s2],
1535           [s3,0,-s1],
1536           [-s2,s1,0];
1537  R=transpose(R);
1538  export R;
1539  return(@r);
1540}
1541//----------------------------------------------------------
1542static proc exAntenna()
1543{
1544  ring @r = (0, K1, K2, Te, Kp, Kc),(Dt, delta), dp;
1545  module R;
1546  R = [Dt, -K1, 0, 0, 0, 0, 0, 0, 0],
1547      [0, Dt+K2/Te, 0, 0, 0, 0, -Kp/Te*delta, -Kc/Te*delta, -Kc/Te*delta],
1548      [0, 0, Dt, -K1, 0, 0, 0, 0, 0],
1549      [0, 0, 0, Dt+K2/Te, 0, 0, -Kc/Te*delta, -Kp/Te*delta, -Kc/Te*delta],
1550      [0, 0, 0, 0, Dt, -K1, 0, 0, 0],
1551      [0, 0, 0, 0, 0, Dt+K2/Te, -Kc/Te*delta, -Kc/Te*delta, -Kp/Te*delta];
1552
1553  R=transpose(R);
1554  export R;
1555  return(@r);
1556}
1557
1558//----------------------------------------------------------
1559
1560static proc exEinstein()
1561{
1562  ring @r = 0,(D(1..4)),dp;
1563  module R =
1564  [D(2)^2+D(3)^2-D(4)^2, D(1)^2, D(1)^2, -D(1)^2, -2*D(1)*D(2), 0, 0, -2*D(1)*D(3), 0, 2*D(1)*D(4)],
1565  [D(2)^2, D(1)^2+D(3)^2-D(4)^2, D(2)^2, -D(2)^2, -2*D(1)*D(2), -2*D(2)*D(3), 0, 0, 2*D(2)*D(4), 0],
1566  [D(3)^2, D(3)^2, D(1)^2+D(2)^2-D(4)^2, -D(3)^2, 0, -2*D(2)*D(3), 2*D(3)*D(4), -2*D(1)*D(3), 0, 0],
1567  [D(4)^2, D(4)^2, D(4)^2, D(1)^2+D(2)^2+D(3)^2, 0, 0, -2*D(3)*D(4), 0, -2*D(2)*D(4), -2*D(1)*D(4)],
1568  [0, 0, D(1)*D(2), -D(1)*D(2), D(3)^2-D(4)^2, -D(1)*D(3), 0, -D(2)*D(3), D(1)*D(4), D(2)*D(4)],
1569  [D(2)*D(3), 0, 0, -D(2)*D(3),-D(1)*D(3), D(1)^2-D(4)^2, D(2)*D(4), -D(1)*D(2), D(3)*D(4), 0],
1570  [D(3)*D(4), D(3)*D(4), 0, 0, 0, -D(2)*D(4), D(1)^2+D(2)^2, -D(1)*D(4), -D(2)*D(3), -D(1)*D(3)],
1571  [0, D(1)*D(3), 0, -D(1)*D(3), -D(2)*D(3), -D(1)*D(2), D(1)*D(4), D(2)^2-D(4)^2, 0, D(3)*D(4)],
1572  [D(2)*D(4), 0, D(2)*D(4), 0, -D(1)*D(4), -D(3)*D(4), -D(2)*D(3), 0, D(1)^2+D(3)^2, -D(1)*D(2)],
1573  [0, D(1)*D(4), D(1)*D(4), 0, -D(2)*D(4), 0, -D(1)*D(3), -D(3)*D(4), -D(1)*D(2), D(2)^2+D(3)^2];
1574
1575  R=transpose(R);
1576  export R;
1577  return(@r);
1578}
1579
1580//----------------------------------------------------------
1581static proc exFlexibleRod()
1582{
1583  ring @r = 0,(D1, delta), dp;
1584  module R;
1585  R = [D1, -D1*delta, -1], [2*D1*delta, -D1-D1*delta^2, 0];
1586
1587  R=transpose(R);
1588  export R;
1589  return(@r);
1590}
1591
1592//----------------------------------------------------------
1593static proc exTwoPendula()
1594{
1595  ring @r=(0,m1,m2,M,g,L1,L2),Dt,dp;
1596  module R = [m1*L1*Dt^2, m2*L2*Dt^2, -1, (M+m1+m2)*Dt^2],
1597             [m1*L1^2*Dt^2-m1*L1*g, 0, 0, m1*L1*Dt^2],
1598             [0, m2*L2^2*Dt^2-m2*L2*g, 0, m2*L2*Dt^2];
1599
1600  R=transpose(R);
1601  export R;
1602  return(@r);
1603}
1604//----------------------------------------------------------
1605static proc exWindTunnel()
1606{
1607  ring @r = (0,a, omega, zeta, k),(D1, delta),dp;
1608  module R = [D1+a, -k*a*delta, 0, 0],
1609             [0, D1, -1, 0],
1610             [0, omega^2, D1+2*zeta*omega, -omega^2];
1611
1612  R=transpose(R);
1613  export R;
1614  return(@r);
1615}
1616
1617/* noncomm examples for leftInverse/rightInverse:
1618
1619LIB "jacobson.lib";
1620    ring w = 0,(x,d),Dp;
1621    def W=nc_algebra(1,1);
1622    setring W;
1623    matrix m[3][3]=[d2,d+1,0],[d+1,0,d3-x2*d],[2d+1, d3+d2, d2];
1624    list J=jacobson(m,0);
1625
1626leftInverse(J[3]); // exist
1627rightInverse(J[3]);
1628
1629leftInverse(J[1]); // zero
1630rightInverse(J[1]);
1631
1632list JJ = jacobson(J[1],0);
1633
1634leftInverse(JJ[3]); // exist
1635rightInverse(JJ[3]);
1636
1637leftInverse(JJ[1]); // exist
1638rightInverse(JJ[1]);
1639
1640leftInverse(JJ[2]); // zero
1641rightInverse(JJ[2]);
1642
1643*/
Note: See TracBrowser for help on using the repository browser.