source: git/Singular/LIB/control.lib @ 2301b7

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