00001
00002
00003 #include <math.h>
00004 #include "complex.h"
00005
00006 #define EPSS 6.e-8
00007 #define MAXIT 100
00008
00009 void laguer(a,m,x,eps,polish)
00010 fcomplex a[],*x;
00011 int m,polish;
00012 float eps;
00013 {
00014 int j,iter;
00015 float err,dxold,cdx,abx;
00016 fcomplex sq,h,gp,gm,g2,g,b,d,dx,f,x1;
00017 void nrerror();
00018
00019 dxold=Cabs(*x);
00020 for (iter=1;iter<=MAXIT;iter++) {
00021 b=a[m];
00022 err=Cabs(b);
00023 d=f=Complex(0.0,0.0);
00024 abx=Cabs(*x);
00025 for (j=m-1;j>=0;j--) {
00026 f=Cadd(Cmul(*x,f),d);
00027 d=Cadd(Cmul(*x,d),b);
00028 b=Cadd(Cmul(*x,b),a[j]);
00029 err=Cabs(b)+abx*err;
00030 }
00031 err *= EPSS;
00032 if (Cabs(b) <= err) return;
00033 g=Cdiv(d,b);
00034 g2=Cmul(g,g);
00035 h=Csub(g2,RCmul(2.0,Cdiv(f,b)));
00036 sq=Csqrt(RCmul((float) (m-1),Csub(RCmul((float) m,h),g2)));
00037 gp=Cadd(g,sq);
00038 gm=Csub(g,sq);
00039 if (Cabs(gp) < Cabs(gm))gp=gm;
00040 dx=Cdiv(Complex((float) m,0.0),gp);
00041 x1=Csub(*x,dx);
00042 if (x->r == x1.r && x->i == x1.i) return;
00043 *x=x1;
00044 cdx=Cabs(dx);
00045 if (iter > 6 && cdx >= dxold) return;
00046 dxold=cdx;
00047 if (!polish)
00048 if (cdx <= eps*Cabs(*x)) return;
00049 }
00050 nrerror("Too many iterations in routine LAGUER");
00051 }
00052
00053 #undef EPSS
00054 #undef MAXIT