source: git/Singular/LIB/solve.lib @ b3ce75

fieker-DuValspielwiese
Last change on this file since b3ce75 was 917fb5, checked in by Hans Schönemann <hannes@…>, 25 years ago
* hannes: removed pause; (scanner.l, febase.*) introduced pause([string]) (standard.lib) git-svn-id: file:///usr/local/Singular/svn/trunk@3237 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 7.4 KB
Line 
1///////////////////////////////////////////////////////////////////////////////
2
3version="$Id: solve.lib,v 1.9 1999-07-06 15:32:57 Singular Exp $";
4info="
5LIBRARY: solve.lib     PROCEDURES TO SOLVE POLYNOMIAL SYSTEMS
6AUTHOR:  Moritz Wenk,  email: wenk@mathematik.uni-kl.de
7
8PROCEDURES:
9 ures_solve(i,..);      find all roots of 0-dimensional ideal i with resultants
10 mp_res_mat(i,..);      multipolynomial resultant matrix of ideal i
11 laguerre_solve(p,..);  find all roots of univariate polynom p
12 interpolate(i,j,d);    interpolate poly from evaluation points i and results j
13";
14
15///////////////////////////////////////////////////////////////////////////////
16
17proc ures_solve( ideal gls, list # )
18"USAGE:   ures_solve(i[,k,l,m]); i ideal, k,l,m integers
19         k=0: use sparse resultant matrix of Gelfand, Kapranov and Zelevinsky
20         k=1: use resultant matrix of Macaulay (k=0 is default)
21         l>0: defines precision of fractional part if ground field is Q
22         m=0,1,2: number of iterations for approximation of roots (default=2)
23ASSUME:  i is a zerodimensional ideal with
24         nvars(basering) = ncols(i) = number of vars actually occuring in i
25RETURN:  list of all (complex) roots of the polynomial system i = 0,
26         of type number if the ground field is the complex numbers,
27         of type string if the ground field is the rational or real numbers
28EXAMPLE: example ures_solve; shows an example
29"
30{
31  int typ=0;
32  int polish=2;
33  int prec=30;
34
35  if ( size(#) >= 1 )
36  {
37    typ= #[1];
38    if ( typ < 0 || typ > 1 )
39    {
40      ERROR("Valid values for second parameter k are:
41      0: use sparse Resultant (default)
42      1: use Macaulay Resultant");
43    }
44  }
45  if ( size(#) >= 2 )
46  {
47    prec= #[2];
48    if ( prec == 0 ) { prec = 30; }
49    if ( prec < 0 )
50    {
51      ERROR("Third parameter l must be positive!");
52    }
53  }
54  if ( size(#) >= 3 )
55  {
56    polish= #[3];
57    if ( polish < 0 || polish > 2 )
58    {
59      ERROR("Valid values for fourth parameter m are:
60      0,1,2: number of iterations for approximation of roots");
61    }
62  }
63
64  if ( size(#) > 3 )
65  {
66    ERROR("only three parameters allowed!");
67  }
68
69  int digits= system("setFloatDigits",prec);
70
71  return(uressolve(gls,typ,polish));
72
73}
74example
75{
76  "EXAMPLE:";echo=2;
77  // compute the intersection points of two curves
78  ring rsq = 0,(x,y),lp;
79  ideal gls=  x2 + y2 - 10, x2 + xy + 2y2 - 16;
80  ures_solve(gls);
81  // result is a list (x,y)-coordinates as strings
82
83  pause();
84  // now with complex coefficient field, precision is 10 digits
85  ring rsc= (real,10,I),(x,y),lp;
86  ideal i = (2+3*I)*x2 + (0.35+I*45.0e-2)*y2 - 8, x2 + xy + (42.7)*y2;
87  ures_solve(i);
88  // result is a list of (x,y)-coordinates of complex numbers
89}
90///////////////////////////////////////////////////////////////////////////////
91
92proc laguerre_solve( poly f, list # )
93"USAGE:   laguerre_solve( p[,l,m]); f poly, l,m integers
94         l>0: defines precision of fractional part if ground field is Q
95         m=0,1,2: number of iterations for approximation of roots (default=2)
96ASSUME:  p is an univariate polynom
97RETURN:  list of all (complex) roots of the polynomial p;
98         of type number if the ground field is the complex numbers,
99         of type string if the ground field is the rational or real numbers
100EXAMPLE: example laguerre_solve; shows an example
101"
102{
103  int polish=2;
104  int prec=30;
105
106  if ( size(#) >= 1 )
107  {
108    prec= #[1];
109    if ( prec == 0 ) { prec = 30; }
110    if ( prec < 0 )
111    {
112      ERROR("Fisrt parameter must be positive!");
113    }
114  }
115  if ( size(#) >= 2 )
116  {
117    polish= #[2];
118    if ( polish < 0 || polish > 2 )
119    {
120      ERROR("Valid values for third parameter are:
121      0,1,2: number of iterations for approximation of roots");
122    }
123  }
124  if ( size(#) > 2 )
125  {
126    ERROR("only two parameters allowed!");
127  }
128
129  int digits= system("setFloatDigits",prec);
130
131  return(laguerre(f,polish));
132
133}
134example
135{
136  "EXAMPLE:";echo=2;
137  // Find all roots of an univariate polynomial using Laguerre's method:
138  ring rs1= 0,(x,y),lp;
139  poly f = 15x5 + x3 + x2 - 10;
140  laguerre_solve(f);
141
142  pause();
143  // Now with 10 digits precision:
144  laguerre_solve(f,10);
145
146  pause();
147  // Now with complex coefficients, precision is 20 digits:
148  ring rsc= (real,20,I),x,lp;
149  poly f = (15.4+I*5)*x^5 + (25.0e-2+I*2)*x^3 + x2 - 10*I;
150  list l = laguerre_solve(f);
151  l;
152}
153///////////////////////////////////////////////////////////////////////////////
154
155proc mp_res_mat( ideal i, list # )
156"USAGE:   mp_res_mat(i[,k]); i ideal, k integer
157         k=0: sparse resultant matrix of Gelfand, Kapranov and Zelevinsky
158         k=1: resultant matrix of Macaulay (k=0 is default)
159ASSUME:  nvars(basering) = ncols(i)-1 = number of vars actually occuring in i,
160         for k=1 i must be homogeneous
161RETURN:  module representing the multipolynomial resultant matrix
162EXAMPLE: example mp_res_mat; shows an example
163"
164{
165  int typ=2;
166
167  if ( size(#) == 1 )
168  {
169    typ= #[1];
170    if ( typ < 0 || typ > 1 )
171    {
172      ERROR("Valid values for third parameter are:
173      0: sparse resultant (default)
174      1: Macaulay resultant");
175    }
176  }
177  if ( size(#) > 1 )
178  {
179    ERROR("only two parameters allowed!");
180  }
181
182  return(mpresmat(i,typ));
183
184}
185example
186{
187  "EXAMPLE:";echo=2;
188  // compute resultant matrix in ring with parameters (sparse resultant matrix)
189  ring rsq= (0,u0,u1,u2),(x1,x2),lp;
190  ideal i= u0+u1*x1+u2*x2,x1^2 + x2^2 - 10,x1^2 + x1*x2 + 2*x2^2 - 16;
191  module m = mp_res_mat(i);
192  print(m);
193  // computing sparse resultant
194  det(m);
195
196  pause();
197  // compute resultant matrix (Macaulay resultant matrix)
198  ring rdq= (0,u0,u1,u2),(x0,x1,x2),lp;
199  ideal h=  homog(imap(rsq,i),x0);
200  hgls;
201  module m = mp_res_mat(h,1);
202  print(m);
203  // computing Macaulay resultant (should be the same as above!)
204  det(m);
205
206  pause();
207  // compute numerical sparse resultant matrix
208  setring rsq;
209  ideal ir= 15+2*x1+5*x2,x1^2 + x2^2 - 10,x1^2 + x1*x2 + 2*x2^2 - 16;
210  module mn = mp_res_mat(ir);
211  print(mn);
212  // computing sparse resultant
213  det(mn);
214}
215///////////////////////////////////////////////////////////////////////////////
216
217proc interpolate( ideal p, ideal w, int d )
218"USAGE:   interpolate(p,v,d); p,v ideals, d int
219ASSUME:  ground field K is the rational numbers,
220         p and v consist of numbers of the ground filed K, p must have
221         n elements, v must have N=(d+1)^n elements where n=nvars(basering)
222         and d=deg(f) (f is the unknown polynomial in K[x1,...,xn])
223COMPUTE: polynomial f with values given by v at points p1,..,pN derived from p;
224         more precisely: consider p as point in K^n and v as N elements in K,
225         let p1,..,pN be the points in K^n obtained by evaluating all monomials
226         of degree 0,1,...,N at p in lexicographical order,
227         then the procedure computes the polynomial f satisfying f(pi) = v[i]
228RETURN:  polynomial f of degree d
229NOTE:    mainly useful for n=1, with f satisfying f(p^(i-1)) = v[i], i=1..d+1
230EXAMPLE: example interpolate; shows an example
231"
232{
233  return(vandermonde(p,w,d));
234}
235example
236{
237  "EXAMPLE:";  echo=2;
238  ring r1 = 0,(x),lp;
239  // determine f with deg(f) = 4 and
240  // v = values of f at points 3^0, 3^1, 3^2, 3^3, 3^4
241  ideal v=16,0,11376,1046880,85949136;
242  interpolate( 3, v, 4 );
243
244  ring r2 = 0,(x,y),dp;
245  // determine f with deg(f) = 3 and
246  // v = values of f at 16 points (2,3)^0=(1,1),...,(2,3)^15=(2^15,3^15)
247  // valuation point (2,3)
248  ideal p = 2,3;
249  ideal v= 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16;
250  interpolate( p,v,3 );
251}
252///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.