37 use lapack95,
only: gebal, hseqr
46 pure function func(x)
result(y)
49 real(
wp),
intent(in) :: x
72 complex(WP),
dimension(1:),
intent(in) :: c
75 complex(WP),
dimension(:),
allocatable,
intent(out) :: r
83 integer,
intent(out) :: error
88 logical,
intent(in),
optional :: BalanceOn
90 integer :: n, nnz, ctr
91 integer,
dimension(1) :: nzlocl, nzloct
92 complex(WP),
dimension(:),
allocatable :: cnz
93 complex(WP),
dimension(:,:),
allocatable :: H
95 integer :: ilo, ihi, info
96 real(WP),
dimension(:),
allocatable,
target :: scale
110 if (all(abs(c) == 0) .EQV. .true.)
then
117 if (
present(balanceon)) usebalance = balanceon
121 integer,
dimension(size(c)) :: c1
123 c1 = merge(1,0,real(c) /= 0 .OR. aimag(c) /= 0)
124 nzlocl = findloc(c1, 1)
125 nzloct = findloc(c1, 1, back=.true.)
130 nnz = nzloct(1) - nzlocl(1)
133 cnz = c(nzlocl(1):nzloct(1))
139 do while (any(abs(cnz(ctr+1:)/cnz(ctr)) >
inf))
141 if (ctr == ubound(cnz,1))
exit
143 nnz = nnz - (ctr - 1)
148 r = [(0, ctr = 1,(n+1-nzloct(1)))]
150 elseif (nnz == 1)
then
151 r = [
complex(WP):: -cnz(1+ctr)/cnz(ctr), (0, ctr = 1,(n+1-nzloct(1)))]
158 h(1,:) = -cnz(ctr+1:)/cnz(ctr)
159 do ctr = 2,ubound(h,1)
160 h(ctr, ctr-1) = (1,0)
166 call gebal(h, ilo=ilo, ihi=ihi, job=
'B',info=info)
180 call hseqr(h, r, ilo=ilo, ihi=ihi, job=
'E', info=info)
183 if (info /= 0) error = -4
186 r = [
complex(wp) :: r, (0, ctr = 1,(n+1-nzloct(1)))]
208 pure subroutine root(a, b, ya, yb, tol, f, x, fx, niter, error)
212 real(wp),
intent(in) :: a
213 real(wp),
intent(in) :: b
214 real(wp),
intent(in) :: ya
215 real(wp),
intent(in) :: yb
216 real(wp),
intent(in) :: tol
218 real(wp),
intent(out) :: x
219 real(wp),
intent(out) :: fx
220 integer,
intent(out) :: niter
227 integer,
intent(out) :: error
229 real(wp) :: aa, bb, cc, fa, fb, fc, xm, ss, dd, ee, pp, qq, rr
233 real(wp),
parameter :: nearzero = 1.0e-20_wp
251 if (abs(fa) <= nearzero)
then
255 else if (abs(fb) <= nearzero)
then
262 if ((fa>0 .AND. fb>0) .OR. (fa<0 .AND. fb<0))
then
275 if ((fc>0 .AND. fb>0) .OR. (fc<0 .AND. fb<0))
then
282 if (abs(fc) < abs(fb))
then
291 tolx = 2.0*eps*abs(bb) + 0.5*tol
295 if (abs(xm) <= tolx .OR. abs(fa) < nearzero)
then
301 if (abs(ee) >= tolx .AND. abs(fa) > abs(fb))
then
303 if (abs(aa - cc) < nearzero)
then
311 pp = ss*(2.0*xm*qq*(qq-rr)-(bb-aa)*(rr-1.0))
312 qq = (qq - 1.0)*(rr - 1.0)*(ss - 1.0)
315 if (pp > nearzero) qq = -qq
317 if ((2.0*pp) < min(3.0*xm*qq-abs(tolx*qq), abs(ee*qq)))
then
334 if (abs(dd) > tolx)
then