From 3a056c4dffd1bdc94d4886a537646c3fc96bbca5 Mon Sep 17 00:00:00 2001 From: Chulwoo Jung Date: Mon, 22 May 2017 18:23:03 -0400 Subject: [PATCH] Re-adding Bisection for SimpleLanczos --- lib/algorithms/Algorithms.h | 1 + lib/algorithms/iterative/bisec.c | 122 +++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 lib/algorithms/iterative/bisec.c diff --git a/lib/algorithms/Algorithms.h b/lib/algorithms/Algorithms.h index 5123c7a1..6768555c 100644 --- a/lib/algorithms/Algorithms.h +++ b/lib/algorithms/Algorithms.h @@ -48,6 +48,7 @@ Author: Peter Boyle // Lanczos support //#include #include +#include #include #include diff --git a/lib/algorithms/iterative/bisec.c b/lib/algorithms/iterative/bisec.c new file mode 100644 index 00000000..b305b833 --- /dev/null +++ b/lib/algorithms/iterative/bisec.c @@ -0,0 +1,122 @@ +#include +#include +#include + +struct Bisection { + +static void get_eig2(int row_num,std::vector &ALPHA,std::vector &BETA, std::vector & eig) +{ + int i,j; + std::vector evec1(row_num+3); + std::vector evec2(row_num+3); + RealD eps2; + ALPHA[1]=0.; + BETHA[1]=0.; + for(i=0;imag(evec2[i+1])) { + swap(evec2+i,evec2+i+1); + swapped=1; + } + } + end--; + for(i=end-1;i>=begin;i--){ + if(mag(evec2[i])>mag(evec2[i+1])) { + swap(evec2+i,evec2+i+1); + swapped=1; + } + } + begin++; + } + + for(i=0;i &c, + std::vector &b, + int n, + int m1, + int m2, + RealD eps1, + RealD relfeh, + std::vector &x, + RealD &eps2) +{ + std::vector wu(n+2); + + RealD h,q,x1,xu,x0,xmin,xmax; + int i,a,k; + + b[1]=0.0; + xmin=c[n]-fabs(b[n]); + xmax=c[n]+fabs(b[n]); + for(i=1;ixmax) xmax= c[i]+h; + if(c[i]-h0.0 ? xmax : -xmin); + if(eps1<=0.0) eps1=eps2; + eps2=0.5*eps1+7.0*(eps2); + x0=xmax; + for(i=m1;i<=m2;i++){ + x[i]=xmax; + wu[i]=xmin; + } + + for(k=m2;k>=m1;k--){ + xu=xmin; + i=k; + do{ + if(xu=m1); + if(x0>x[k]) x0=x[k]; + while((x0-xu)>2*relfeh*(fabs(xu)+fabs(x0))+eps1){ + x1=(xu+x0)/2; + + a=0; + q=1.0; + for(i=1;i<=n;i++){ + q=c[i]-x1-((q!=0.0)? b[i]*b[i]/q:fabs(b[i])/relfeh); + if(q<0) a++; + } + // printf("x1=%e a=%d\n",x1,a); + if(ax1) x[a]=x1; + } + }else x0=x1; + } + x[k]=(x0+xu)/2; + } +} +}