#include #include "nr.h" using namespace std; void NR::period(Vec_I_DP &x, Vec_I_DP &y, const DP ofac, const DP hifac, Vec_O_DP &px, Vec_O_DP &py, int &nout, int &jmax, DP &prob) { const DP TWOPI=6.283185307179586476; int i,j; DP ave,c,cc,cwtau,effm,expy,pnow,pymax,s,ss,sumc,sumcy,sums,sumsh, sumsy,swtau,var,wtau,xave,xdif,xmax,xmin,yy,arg,wtemp; int n=x.size(); int np=px.size(); Vec_DP wi(n),wpi(n),wpr(n),wr(n); nout=0.5*ofac*hifac*n; if (nout > np) nrerror("output arrays too short in period"); avevar(y,ave,var); if (var == 0.0) nrerror("zero variance in period"); xmax=xmin=x[0]; for (j=0;j xmax) xmax=x[j]; if (x[j] < xmin) xmin=x[j]; } xdif=xmax-xmin; xave=0.5*(xmax+xmin); pymax=0.0; pnow=1.0/(xdif*ofac); for (j=0;j= pymax) pymax=py[jmax=i]; pnow += 1.0/(ofac*xdif); } expy=exp(-pymax); effm=2.0*nout/ofac; prob=effm*expy; if (prob > 0.01) prob=1.0-pow(1.0-expy,effm); }