home *** CD-ROM | disk | FTP | other *** search
- namull(root,n,eps,max)
-
- /* subroutine finds n complex roots of the equation f(x) = 0 */
- /* using Muller's method. f(x) may be transcendental and */
- /* complex. */
-
- int max,*n;
- float eps,root[];
-
- {
- int i1=1,i2=2,i3=3,i4=4,inf,j,j1,j2,k,k1,k2,m,mm;
- float alam[2],b1[2],b2[2],b3[2],d[2],delta[2],f1[2],f2[2],f3[2];
- float fprt[2],g[2],h[2],temp[2],rt[2],xn[2],s;
- static float one[2]={1.,0.},two[2]={-2.,0.},four[2]={4.,0.};
- extern double fabs(),sqrt();
-
- k = 0;
- reit: k = k + 1;
- mm = 0;
- k2 = k + k;
- k1 = k2 - 1;
- if(root[k1-1] != 0.0 || root[k2-1] != 0.0)
- {
- rt[0] = 0.9 * root[k1-1];
- rt[1] = 0.9 * root[k2-1];
- m = 1;
- }
- else
- {
- rt[0] = -1.0;
- rt[1] = 0.0;
- h[0] = -1.0;
- h[1] = 0.0;
- alam[0] = -0.5;
- alam[1] = 0.0;
- m = 3;
- }
- inf = 1;
- while(inf == 1)
- {
- value(rt,fprt);
- s = sqrt(fprt[0]*fprt[0] + fprt[1]*fprt[1]);
- if(s < eps)
- {
- root[k1-1] = xn[0];
- root[k2-1] = xn[1];
- if(k != *n) goto reit;
- return;
- }
- mm = mm + 1;
- if(mm >= max)
- {
- *n = k - 1;
- return;
- }
- if(k != 1)
- {
- for(j = 1; j <= k-1; j++)
- {
- j2 = j + j;
- j1 = j2 - 1;
- temp[0] = rt[0] - root[j1-1];
- temp[1] = rt[1] - root[j2-1];
- cxarth(fprt,temp,fprt,i4);
- }
- }
- switch(m){
- case 1:
- f1[0] = fprt[0];
- f1[1] = fprt[1];
- rt[0] = 1.1 * root[k1-1];
- rt[1] = 1.1 * root[k2-1];
- m = 2;
- break;
- case 2:
- f2[0] = fprt[0];
- f2[1] = fprt[1];
- h[0] = root[k1-1] - rt[0];
- h[1] = root[k2-1] - rt[1];
- alam[0] = .2 * root[k1-1];
- alam[1] = .2 * root[k2-1];
- rt[0] = root[k1-1];
- rt[1] = root[k2-1];
- m = 5;
- break;
- case 3:
- f1[0] = fprt[0];
- f1[1] = fprt[1];
- rt[0] = 1.0;
- rt[1] = 0.0;
- m = 4;
- break;
- case 4:
- f2[0] = fprt[0];
- f2[1] = fprt[1];
- rt[0] = 0.0;
- rt[1] = 0.0;
- m = 5;
- break;
- case 6:
- f1[0] = f2[0];
- f1[1] = f2[1];
- f2[0] = f3[0];
- f2[1] = f3[1];
- case 5:
- f3[0] = fprt[0];
- f3[1] = fprt[1];
- cxarth(one,alam,delta,i1);
- cxarth(f1,alam,b1,i3);
- cxarth(b1,alam,b1,i3);
- cxarth (delta,delta,b2,i3);
- cxarth(b2,f2,b2,i3);
- cxarth(alam,delta,b3,i1);
- cxarth(b3,f3,b3,i3);
- cxarth(b1,b2,g,i2);
- cxarth(g,b3,g,i1);
- cxarth(f1,alam,b1,i3);
- cxarth(f2,delta,b2,i3);
- cxarth(b1,b2,b2,i2);
- cxarth(b2,f3,b2,i1);
- cxarth(b2,alam,b2,i3);
- cxarth(b2,delta,b2,i3);
- cxarth(b2,f3,b2,i3);
- cxarth(b2,four,b2,i3);
- cxarth(g,g,b1,i3);
- cxarth(b1,b2,d,i2);
- cxsqrt(d,d);
- cxarth(g,d,b1,i1);
- cxarth(g,d,b2,i2);
- d[0] = (b1[0] - b1[1])*(b1[0] + b1[1]);
- d[1] = (b2[0] - b2[1])*(b2[0] + b2[1]);
- if(d[0] >= d[1])
- {
- d[0] = b1[0];
- d[1] = b1[1];
- }
- else
- {
- d[0] = b2[0];
- d[1] = b2[1];
- }
- cxarth(f3,delta,b1,i3);
- cxarth(b1,two,b1,i3);
- cxarth(b1,d,alam,i4);
- cxarth(h,alam,h,i3);
- cxarth(rt,h,xn,i1);
- rt[0] = xn[0];
- rt[1] = xn[1];
- m = 6;
- }
- }
- }