/* chousv.c CCMATH mathematics library source code. * * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. * This code may be redistributed under the terms of the GNU library * public license (LGPL). ( See the lgpl.license file for details.) * ------------------------------------------------------------------------ */ #include #include "complex.h" void chousv(Cpx *a,double *d,double *dp,int n) { double sc,x,y; Cpx cc,u,*qs; int i,j,k,m,e; Cpx *qw,*pc,*p,*q; qs=(Cpx *)calloc(2*n,sizeof(Cpx)); q=qs+n; for(j=0,pc=a; j0.){ sc=sqrt(sc); p=pc+1; y=sc+(x=sqrt(p->re*p->re+p->im*p->im)); if(x>0.){ cc.re=p->re/x; cc.im=p->im/x;} else{ cc.re=1.; cc.im=0.;} q->re= -cc.re; q->im= -cc.im; x=1./sqrt(2.*sc*y); y*=x; for(i=0,qw=pc+1; ire - (u.im=qw[i].im)*p->im; qs[i].im+=u.re*p->im + u.im*p->re; ++p; for(k=i+1; kre - qw[k].im*p->im; qs[i].im+=qw[k].im*p->re + qw[k].re*p->im; qs[k].re+=u.re*p->re + u.im*p->im; qs[k].im+=u.im*p->re - u.re*p->im; } y+=u.re*qs[i].re + u.im*qs[i].im; } for(i=0; ire-=qw[i].re*qs[k].re + qw[i].im*qs[k].im +qs[i].re*qw[k].re + qs[i].im*qw[k].im; p->im-=qw[i].im*qs[k].re - qw[i].re*qs[k].im +qs[i].im*qw[k].re - qs[i].re*qw[k].im; } } } d[j]=pc->re; dp[j]=sc; } d[j]=pc->re; cc= *(pc+1); d[j+1]=(pc+=n+1)->re; dp[j]=sc=sqrt(cc.re*cc.re+cc.im*cc.im); q->re=cc.re/=sc; q->im=cc.im/=sc; for(i=0,m=n+n,p=pc; ire=p->im=0.; pc->re=1.; (pc-=n+1)->re=1.; qw=pc-n; for(m=2; mre=1.; jre-qw[i].im*q->im; u.im+=qw[i].re*q->im+qw[i].im*q->re; } for(i=0,q=p,u.re+=u.re,u.im+=u.im; ire-=u.re*qw[i].re+u.im*qw[i].im; q->im-=u.im*qw[i].re-u.re*qw[i].im; } } for(i=0,p=qw+m-1; ire=p->im=0.; (pc-=n+1)->re=1.; } for(j=1,p=a+n+1,q=qs+n,u.re=1.,u.im=0.; jre-u.im*q->im; u.im=u.im*q->re+u.re*q->im; u.re=sc; for(i=1; ire-u.im*p->im; p->im=u.re*p->im+u.im*p->re; p->re=sc; } } free(qs); }