#                              Ren-Cang Li, June 1, 1996
#                              na.rcli@na-net.ornl.gov

Iterndcx34dcy34:=proc(x0L:vector, cx10L, x0U:vector,cx10U, xM:vector)
  local niter, xL, cx1L, yL, xU, cx1U, yU, eps, x0, y0, x1, y1, 
	cx10, cx11, yM, cx1M, dx;
  eps:=10^(-Digits+30): niter:=0:
  xL:=x0L: cx1L:=cx10L: xU:=x0U: cx1U:=cx10U: dx:=vector(7):
  #
  cx1fixedf3out(xL,dx,cx1L): yL:=dx[2]-dx[3]+dx[6]-dx[7]:
  cx1fixedf3out(xU,dx,cx1U): yU:=dx[2]-dx[3]+dx[6]-dx[7]:
  if yL*yU>=0 then
     print(`Warning: there may be two zeros or NONE.`);
     print(`Please INTERRUPT to stop!`);
  fi:
  x0:=xL: y0:=yL: cx10:=cx1L: x1:=xU: y1:=yU: cx11:=cx1U:
  cx1M:=cx11-y1*((cx11-cx10)/(y1-y0)):
  if cx1M<cx1L or cx1M>cx1U then
     cx1M:=(cx1L+cx1U)/2:
     xM:=evalm((xL+xU)/2):
  else
     xM:=evalm((y0/(y0-y1))*x1+(y1/(y1-y0))*x0):
  fi:
  cx1fixedf3out(xM, dx, cx1M): yM:=dx[2]-dx[3]+dx[6]-dx[7]:
  # print(cx1M); print(cx11); print(niter); print(yM); print(eps);
  while abs(cx1M-cx11)>eps*abs(cx1M) and niter<101 and abs(yM)>eps do
        niter := niter + 1:
        if yL*yM>=0 then
           xL:=xM: yL:=yM: cx1L:=cx1M:
        else
           xU:=xM: yU:=yM: cx1U:=cx1M:
        fi:
        x0:=x1: y0:=y1: cx10:=cx11:
        x1:=xM: y1:=yM: cx11:=cx1M:
        cx1M:=cx11-y1*((cx11-cx10)/(y1-y0)):
        if cx1M<cx1L or cx1M>cx1U then
           cx1M:=(cx1L+cx1U)/2:
           xM:=evalm((xL+xU)/2):
        else
           xM:=evalm((y0/(y0-y1))*x1+(y1/(y1-y0))*x0):
        fi:
        cx1fixedf3out(xM, dx, cx1M):
        yM:=dx[2]-dx[3]+dx[6]-dx[7]:
	# print(yM);
  od:
  if niter>100 then
     print(`In Iterndcx34dcy34: Over 100 iterations`):
  fi:
  cx1M;
end:
