USE cbmat
REAL alpha,Re
COMPLEX c
ASK alpha,Re
a2=alpha*alpha
SUBROUTINE everything(INTEGER N)
yinf=2
h=yinf/N
ARRAY(-2..2) OF REAL d0,d1,d2,d4
d0(-2)=0; d0(-1)=1/6; d0(0)=2/3; d0(1)=1/6; d0(2)=0
d1(-2)=0; d1(-1)=-1/2/h; d1(0)=0; d1(1)=1/2/h; d1(2)=0
d2(-2)=1/12/h/h; d2(-1)=2/3/h/h; d2(0)=-3/2/h/h; d2(1)=2/3/h/h; d2(2)=1/12/h/h
d4(-2)=1/h/h/h/h; d4(-1)=-4/h/h/h/h; d4(0)=6/h/h/h/h; d4(1)=-4/h/h/h/h; d4(2)=1/h/h/h/h
ARRAY(-1..N+1) OF REAL y,U,Uyy
DO y(i)=h*i FOR ALL i
SUBROUTINE Poiseuille
DO U(i)=y(i)*[yinf-y(i)]; Uyy(i)=-2 FOR ALL i
END Poiseuille
COMPLEX A(1..N-1,-2..2), B(1..N-1,-2..2)
ARRAY(1..N-1) OF COMPLEX psi,zetaold,psistar,zstar
SUBROUTINE BuildMats
LOOP FOR i=1 TO N-1 AND j=-2 TO 2
B(i,j)=d2(j)-a2*d0(j)
A(i,j)=(c-U(i))*B(i,j)+Uyy(i)*d0(j)+I/alpha/Re*[d4(j)-2*a2*d2(j)+a2*a2*d0(j)]
REPEAT LOOP
B(1,0)=~-B(1,-1)/2+B(1,-2)
A(1,0)=~-A(1,-1)/2+A(1,-2)
B(2,-1)=~-B(2,-2)/2
A(2,-1)=~-A(2,-2)/2
B(N-1,0)=~-B(N-1,1)/2+B(N-1,2)
A(N-1,0)=~-A(N-1,1)/2+A(N-1,2)
B(N-2,1)=~-B(N-2,2)/2
A(N-2,1)=~-A(N-2,2)/2
END BuildMats
SUBROUTINE eigenval
c=0.3
DO
BuildMats; LUdecomp A
zetaold=B*psi; psi=A\zetaold
zstar=psistar/A; psistar=zstar*B
dc=-(zstar*zetaold)/(psistar*psi)
c=c+dc
psi=psi*ABS[psi(1)]/psi(1)/MOD(psi)
zstar=zstar/(psistar*psi)
psistar=psistar/(psistar*psi)
WHILE ABS(dc)>1.E-8
END eigenval
Poiseuille
DO psi(i)=U(i)*(1-U(i)) FOR ALL i
psistar=psi
eigenval
END everything
everything(2000)
c_ref=c
WRITE BY NAME "#",alpha,Re
DO
everything(N)
WRITE N,ABS(c-c_ref),c
FOR N IN (10,15,20,30,50,70,100,150,200,300,500,700,1000)