source: git/Singular/LIB/control.lib @ 91c7251

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