#!../src/tops  -s ../sys  -u ../usr

"speig_near_shift" missing
IF 
    # "tops not compiled with ARPACK; cannot run speig" . nl
    halt 
THEN

"zggev" missing
IF 
    # "tops not compiled with LAPACK; cannot run speig" . nl
    halt 
THEN

# Create the two tridiagonal matrices used in ARPACK/EXAMPLES/SYM/dsdrv4.f,
#
#         [  2/h  -1/h           ]       [ 2h/3   h/6          ]
#     A = [ -1/h   2/h  -1/h     ]   B = [  h/6  2h/3   h/6    ]
#         [       -1/h   2/h   . ]       [        h/6  2h/3  . ]
#         [               .    . ]       [              .    . ]
#
# and compare eigenvalues computed with ARPACK's dsaupd to those
# computed with LAPACK's zggev.
#
#  n = matrix size
#  h = 1/(n+1)

10        is n
1 n 1 + / is h

n speye 2 h / spscale is A_diag
n speye list: 2 n thru ; spcatch  # n x n-1 with 1's on subdiagonal
n 1 spnull 2 spparkn              # n x n   with 1's on subdiagonal
-1 h / spscale                   is A_subdiag
A_diag A_subdiag + spflip_sym    is A

n speye 2 h * 3 / spscale is B_diag
n speye list: 2 n thru ; spcatch  # n x n-1 with 1's on subdiagonal
n 1 spnull 2 spparkn              # n x n   with 1's on subdiagonal
h 6 / spscale                    is B_subdiag
B_diag B_subdiag + spflip_sym    is B

A dense n n null complex, B dense n n null complex, zggev
drop drop # alpha beta
/by       # alpha/beta = eigenvalues
.m nl

2   is nModes   # the number of modes desired near the shift
500 is sigma    # the shift location (in eigenvalue, not frequency, units)

A B sigma nModes speig_near_shift
is Sturm
is eVec
is eVal
" eigenvalues: " . nl eVal .m nl
Sturm .i " eigenvalues are below the shift of " . sigma . nl
" max error: " . nl
A eVec * B eVec * eVal diagpost - abs maxfetch drop drop .m nl
