12 int i, j, jj, l, N, NM1, NN, NZ, zerok;
15 double bnd, df, dx, factor, ff, moduli_max, moduli_min, sc,
x, xm;
16 double aa, bb, cc, lzi, lzr, sr, szi, szr, t, u, xx, xxx, yy;
18 const double RADFAC = 3.14159265358979323846/180;
19 const double lb2 = log(2.0);
20 const double lo = DBL_MIN/DBL_EPSILON;
21 const double cosr = cos(94.0*RADFAC);
22 const double sinr = sin(94.0*RADFAC);
24 if ((*Degree) > MAXDEGREE){
25 cout <<
"\nThe entered Degree is greater than MAXDEGREE. Exiting rpoly. No further action taken.\n";
40 zeror[j] = zeroi[j] = 0.0;
48 for (i = 0; i < NN; i++)
56 zeror[(*Degree) - 1] = -(p[1]/p[0]);
57 zeroi[(*Degree) - 1] = 0.0;
60 Quad_ak1(p[0], p[1], p[2], &zeror[(*Degree) - 2], &zeroi[(*Degree) - 2], &zeror[(*Degree) - 1], &zeroi[(*Degree) - 1]);
70 for (i = 0; i < NN; i++){
72 if (x > moduli_max) moduli_max = x;
73 if ((x != 0) && (x < moduli_min)) moduli_min = x;
84 if (((sc <= 1.0) && (moduli_max >= 10)) || ((sc > 1.0) && (DBL_MAX/sc >= moduli_max))){
85 sc = ((sc == 0) ? DBL_MIN : sc);
86 l = (int)(log(sc)/lb2 + 0.5);
89 for (i = 0; i < NN; i++) p[i] *= factor;
95 for (i = 0; i < NN; i++) pt[i] = fabs(p[i]);
102 x = exp((log(-pt[N]) - log(pt[0]))/(
double)N);
107 x = ((xm < x) ? xm : x);
117 for (i = 1; i < NN; i++) ff = ff *xm + pt[i];
126 for (i = 1; i < N; i++){
133 }
while (fabs(dx/x) > 0.005);
139 for (i = 1; i < N; i++) K[i] = (
double)(N - i)*p[i]/((
double)N);
144 zerok = ((K[NM1] == 0) ? 1 : 0);
146 for (jj = 0; jj < 5; jj++) {
150 for (i = 0; i < NM1; i++){
155 zerok = ((K[NM1] == 0) ? 1 : 0);
161 for (i = 0; i < NM1; i++){
163 K[j] = t*K[j - 1] + p[j];
166 zerok = ((fabs(K[NM1]) <= fabs(bb)*DBL_EPSILON*10.0) ? 1 : 0);
172 for (i = 0; i < N; i++) temp[i] = K[i];
176 for (jj = 1; jj <= 20; jj++){
182 xxx = -(sinr*yy) + cosr*xx;
183 yy = sinr*xx + cosr*yy;
190 Fxshfr_ak1(20*jj, &NZ, sr, bnd, K, N, p, NN, qp, u, &lzi, &lzr, &szi, &szr);
203 for (i = 0; i < NN; i++) p[i] = qp[i];
213 for (i = 0; i < N; i++) K[i] = temp[i];
221 cout <<
"\nFailure. No convergence after 20 shifts. Program terminated.\n";
229 cout <<
"\nThe leading coefficient is zero. No further action taken. Program terminated.\n";
236 void Fxshfr_ak1(
int L2,
int* NZ,
double sr,
double v,
double K[
MDP1],
int N,
double p[MDP1],
int NN,
double qp[MDP1],
double u,
double* lzi,
double* lzr,
double* szi,
double* szr)
246 int fflag, i, iFlag = 1, j, spass, stry, tFlag, vpass, vtry;
247 double a, a1, a3, a7, b, betas, betav, c,
d, e,
f, g, h, oss, ots=0, otv=0, ovv,
s, ss, ts, tss, tv, tvv, ui, vi, vv;
251 betav = betas = 0.25;
258 tFlag =
calcSC_ak1(N, a, b, &a1, &a3, &a7, &c, &d, &e, &f, &g, &h, K, u, v, qk);
260 for (j = 0; j < L2; j++){
264 nextK_ak1(N, tFlag, a, b, a1, &a3, &a7, K, qk, qp);
265 tFlag =
calcSC_ak1(N, a, b, &a1, &a3, &a7, &c, &d, &e, &f, &g, &h, K, u, v, qk);
266 newest_ak1(tFlag, &ui, &vi, a, a1, a3, a7, b, c, d, f, g, h, u, v, K, N, p);
272 ss = ((K[N - 1] != 0.0) ? -(p[N]/K[N - 1]) : 0.0);
276 if ((j != 0) && (tFlag != 3)){
280 tv = ((vv != 0.0) ? fabs((vv - ovv)/vv) : tv);
281 ts = ((ss != 0.0) ? fabs((ss - oss)/ss) : ts);
285 tvv = ((tv < otv) ? tv*otv : 1.0);
286 tss = ((ts < ots) ? ts*ots : 1.0);
290 vpass = ((tvv < betav) ? 1 : 0);
291 spass = ((tss < betas) ? 1 : 0);
293 if ((spass) || (vpass)){
298 for (i = 0; i < N; i++) svk[i] = K[i];
308 if ((fflag && ((fflag = 0) == 0)) && ((spass) && (!vpass || (tss < tvv)))){
313 QuadIT_ak1(N, NZ, ui, vi, szr, szi, lzr, lzi, qp, NN, &a, &b, p, qk, &a1, &a3, &a7, &c, &d, &e, &f, &g, &h, K);
315 if ((*NZ) > 0)
return;
324 if (stry || (!spass)){
328 for (i = 0; i < N; i++) K[i] = svk[i];
334 RealIT_ak1(&iFlag, NZ, &s, N, p, NN, qp, szr, szi, K, qk);
336 if ((*NZ) > 0)
return;
356 for (i = 0; i < N; i++) K[i] = svk[i];
360 if (!vpass || vtry)
break;
367 tFlag =
calcSC_ak1(N, a, b, &a1, &a3, &a7, &c, &d, &e, &f, &g, &h, K, u, v, qk);
382 void QuadSD_ak1(
int NN,
double u,
double v,
double p[
MDP1],
double q[MDP1],
double* a,
double* b)
389 q[1] = *a = -((*b)*u) + p[1];
391 for (i = 2; i < NN; i++){
392 q[i] = -((*a)*u + (*b)*v) + p[i];
400 int calcSC_ak1(
int N,
double a,
double b,
double* a1,
double* a3,
double* a7,
double* c,
double* d,
double* e,
double* f,
double* g,
double* h,
double K[
MDP1],
double u,
double v,
double qk[MDP1])
414 if (fabs((*c)) <= (100.0*DBL_EPSILON*fabs(K[N - 1]))) {
415 if (fabs((*d)) <= (100.0*DBL_EPSILON*fabs(K[N - 2])))
return dumFlag;
419 if (fabs((*d)) >= fabs((*c))){
424 *a3 = (*e)*((*g) + a) + (*h)*(b/(*d));
426 *a7 = (*h) + ((*f) + u)*a;
433 *a3 = (*e)*a + ((*g) + (*h)/(*c))*b;
434 *a1 = -(a*((*d)/(*c))) + b;
435 *a7 = (*g)*(*d) + (*h)*(*f) + a;
441 void nextK_ak1(
int N,
int tFlag,
double a,
double b,
double a1,
double* a3,
double* a7,
double K[
MDP1],
double qk[MDP1],
double qp[MDP1])
451 for (i = 2; i < N; i++) K[i] = qk[i - 2];
456 temp = ((tFlag == 1) ? b : a);
458 if (fabs(a1) > (10.0*DBL_EPSILON*fabs(temp))){
464 K[1] = -((*a7)*qp[0]) + qp[1];
466 for (i = 2; i < N; i++) K[i] = -((*a7)*qp[i - 1]) + (*a3)*qk[i - 2] + qp[i];
475 for (i = 2; i < N; i++) K[i] = -((*a7)*qp[i - 1]) + (*a3)*qk[i - 2];
481 void newest_ak1(
int tFlag,
double* uu,
double* vv,
double a,
double a1,
double a3,
double a7,
double b,
double c,
double d,
double f,
double g,
double h,
double u,
double v,
double K[
MDP1],
int N,
double p[MDP1])
485 double a4, a5, b1, b2, c1, c2, c3, c4, temp;
493 a5 = c + (u + v*f)*d;
497 a5 = (f + u)*c + v*d;
503 b2 = -(K[N - 2] + b1*p[N - 1])/p[N];
507 c4 = -(c2 + c3) + c1;
508 temp = -c4 + a5 + b1*a4;
510 *uu= -((u*(c3 + c2) + v*(b1*a1 + b2*a7))/temp) + u;
511 *vv = v*(1.0 + c4/temp);
519 void QuadIT_ak1(
int N,
int* NZ,
double uu,
double vv,
double* szr,
double* szi,
double* lzr,
double* lzi,
double qp[
MDP1],
int NN,
double* a,
double* b,
double p[MDP1],
double qk[MDP1],
double* a1,
double* a3,
double* a7,
double* c,
double* d,
double* e,
double* f,
double* g,
double* h,
double K[MDP1])
524 int i, j = 0, tFlag, triedFlag = 0;
525 double ee, mp, omp, relstp=0, t, u, ui, v, vi, zm;
532 Quad_ak1(1.0, u, v, szr, szi, lzr, lzi);
537 if (fabs(fabs(*szr) - fabs(*lzr)) > 0.01*fabs(*lzr))
break;
543 mp = fabs(-((*szr)*(*b)) + (*a)) + fabs((*szi)*(*b));
548 ee = 2.0*fabs(qp[0]);
551 for (i = 1; i < N; i++) ee = ee*zm + fabs(qp[i]);
553 ee = ee*zm + fabs((*a) + t);
554 ee = (9.0*ee + 2.0*fabs(t) - 7.0*(fabs((*a) + t) + zm*fabs((*b))))*DBL_EPSILON;
569 if ((relstp <= 0.01) && (mp >= omp) && (!triedFlag)){
573 relstp = ((relstp < DBL_EPSILON) ? sqrt(DBL_EPSILON) : sqrt(relstp));
580 for (i = 0; i < 5; i++){
581 tFlag =
calcSC_ak1(N, *a, *b, a1, a3, a7, c, d, e, f, g, h, K, u, v, qk);
582 nextK_ak1(N, tFlag, *a, *b, *a1, a3, a7, K, qk, qp);
596 tFlag =
calcSC_ak1(N, *a, *b, a1, a3, a7, c, d, e, f, g, h, K, u, v, qk);
597 nextK_ak1(N, tFlag, *a, *b, *a1, a3, a7, K, qk, qp);
598 tFlag =
calcSC_ak1(N, *a, *b, a1, a3, a7, c, d, e, f, g, h, K, u, v, qk);
599 newest_ak1(tFlag, &ui, &vi, *a, *a1, *a3, *a7, *b, *c, *d, *f, *g, *h, u, v, K, N, p);
603 relstp = fabs((-v + vi)/vi);
613 void RealIT_ak1(
int* iFlag,
int* NZ,
double* sss,
int N,
double p[
MDP1],
int NN,
double qp[MDP1],
double* szr,
double* szi,
double K[MDP1],
double qk[MDP1])
622 int i, j = 0, nm1 = N - 1;
623 double ee, kv, mp, ms, omp, pv,
s, t=0;
633 for (i = 1; i < NN; i++) qp[i] = pv = pv*s + p[i];
640 ee = 0.5*fabs(qp[0]);
641 for (i = 1; i < NN; i++) ee = ee*ms + fabs(qp[i]);
646 if (mp <= 20.0*DBL_EPSILON*(2.0*ee - mp)){
660 if ((fabs(t) <= 0.001*fabs(-t + s)) && (mp > omp)){
677 for (i = 1; i < N; i++) qk[i] = kv = kv*s + K[i];
679 if (fabs(kv) > fabs(K[nm1])*10.0*DBL_EPSILON){
683 for (i = 1; i < N; i++) K[i] = t*qk[i - 1] + qp[i];
688 for (i = 1; i < N; i++) K[i] = qk[i - 1];
692 for (i = 1; i < N; i++) kv = kv*s + K[i];
694 t = ((fabs(kv) > (fabs(K[nm1])*10.0*DBL_EPSILON)) ? -(pv/kv) : 0.0);
704 void Quad_ak1(
double a,
double b1,
double c,
double* sr,
double* si,
double* lr,
double* li)
713 *sr = *si = *lr = *li = 0.0;
716 *sr = ((b1 != 0) ? -(c/b1) : *sr);
728 if (fabs(b) < fabs(c)){
729 e = ((c >= 0) ? a : -a);
730 e = -e + b*(b/fabs(c));
731 d = sqrt(fabs(e))*sqrt(fabs(c));
734 e = -((a/b)*(c/b)) + 1.0;
735 d = sqrt(fabs(e))*(fabs(b));
741 d = ((b >= 0) ? -d : d);
743 *sr = ((*lr != 0) ? (c/(*lr))/a : *sr);
void newest_ak1(int tFlag, double *uu, double *vv, double a, double a1, double a3, double a7, double b, double c, double d, double f, double g, double h, double u, double v, double K[MDP1], int N, double p[MDP1])
void RealIT_ak1(int *iFlag, int *NZ, double *sss, int N, double p[MDP1], int NN, double qp[MDP1], double *szr, double *szi, double K[MDP1], double qk[MDP1])
void nextK_ak1(int N, int tFlag, double a, double b, double a1, double *a3, double *a7, double K[MDP1], double qk[MDP1], double qp[MDP1])
void QuadIT_ak1(int N, int *NZ, double uu, double vv, double *szr, double *szi, double *lzr, double *lzi, double qp[MDP1], int NN, double *a, double *b, double p[MDP1], double qk[MDP1], double *a1, double *a3, double *a7, double *c, double *d, double *e, double *f, double *g, double *h, double K[MDP1])
void QuadSD_ak1(int NN, double u, double v, double p[MDP1], double q[MDP1], double *a, double *b)
int calcSC_ak1(int N, double a, double b, double *a1, double *a3, double *a7, double *c, double *d, double *e, double *f, double *g, double *h, double K[MDP1], double u, double v, double qk[MDP1])
TFSIMD_FORCE_INLINE const tfScalar & x() const
void rpoly_ak1(double op[MDP1], int *Degree, double zeror[MAXDEGREE], double zeroi[MAXDEGREE])
void Fxshfr_ak1(int L2, int *NZ, double sr, double v, double K[MDP1], int N, double p[MDP1], int NN, double qp[MDP1], double u, double *lzi, double *lzr, double *szi, double *szr)
void Quad_ak1(double a, double b1, double c, double *sr, double *si, double *lr, double *li)