Пример #1
0
 void realRootsSturm(const double lb, const double ub, std::vector<double> &roots) const
 {
     if ( coef[0] == 0 )
     {
         Internal::SturmRootFinder<deg-1> sturm( coef.tail(deg) );
         sturm.realRoots( lb, ub, roots );
     } else {
         Internal::SturmRootFinder<deg> sturm( coef );
         sturm.realRoots( lb, ub, roots );
     }
 }
Пример #2
0
 void realRootsSturm(const double lb, const double ub, std::vector<double> &roots) const
 {
     if ( coef[0] == 0 )
     {
         int deg = coef.rows()-1;
         Internal::SturmRootFinder<Eigen::Dynamic> sturm( coef.tail(deg) );
         sturm.realRoots( lb, ub, roots );
     } else {
         Internal::SturmRootFinder<Eigen::Dynamic> sturm( coef );
         sturm.realRoots( lb, ub, roots );
     }
 }
Пример #3
0
void valsymtri(real_t d[], real_t bb[], int n, int n1, int n2,
					real_t val[], real_t em[])
{
	real_t sturm(real_t [], real_t [], int, real_t, int, real_t,
					real_t, int *, real_t *, real_t *);
	int k,count,ext,extrapolate;
	real_t max,x,y,macheps,norm,re,machtol,ub,lb,lambda,
			c,fc,b,fb,a,fa,dd,fd,fdb,fda,w,mb,tol,m,p,q;

	macheps=em[0];
	norm=em[1];
	re=em[2];
	machtol=norm*macheps;
	max=norm/macheps;
	count=0;
	ub=1.1*norm;
	lb = -ub;
	lambda=ub;
	for (k=n1; k<=n2; k++) {
		y=ub;
		lb = -1.1*norm;
		x=lb;

		/* look for the zero of the polynomial function */

		b=x;
		fb=sturm(d,bb,n,x,k,machtol,max,&count,&lb,&ub);
		a=x=y;
		fa=sturm(d,bb,n,x,k,machtol,max,&count,&lb,&ub);
		c=a;
		fc=fa;
		ext=0;
		extrapolate=1;
		while (extrapolate) {
			if (fabs(fc) < fabs(fb)) {
				if (c != a) {
					dd=a;
					fd=fa;
				}
				a=b;
				fa=fb;
				b=x=c;
				fb=fc;
				c=a;
				fc=fa;
			}
			tol=fabs(x)*re+machtol;
			m=(c+b)*0.5;
			mb=m-b;
			if (fabs(mb) > tol) {
				if (ext > 2)
					w=mb;
				else {
					if (mb == 0.0)
						tol=0.0;
					else
						if (mb < 0.0) tol = -tol;
					p=(b-a)*fb;
					if (ext <= 1)
						q=fa-fb;
					else {
						fdb=(fd-fb)/(dd-b);
						fda=(fd-fa)/(dd-a);
						p *= fda;
						q=fdb*fa-fda*fb;
					}
					if (p < 0.0) {
						p = -p;
						q = -q;
					}
					w=(p<FLT_MIN || p<=q*tol) ? tol : ((p<mb*q) ? p/q : mb);
				}
				dd=a;
				fd=fa;
				a=b;
				fa=fb;
				x = b += w;
				fb=sturm(d,bb,n,x,k,machtol,max,&count,&lb,&ub);
				if ((fc >= 0.0) ? (fb >= 0.0) : (fb <= 0.0)) {
					c=a;
					fc=fa;
					ext=0;
				} else
					ext = (w == mb) ? 0 : ext+1;
			} else
				break;
		}
		y=c;

		/* end of the zero finding procedure */

		val[k] = lambda = (x > lambda) ? lambda : x;
		if (ub > x)
			ub = (x > y) ? x : y;
	}
	em[3]=count;
}