# Let g(x,y) be defined by Fxy, and let f(x,y,z) be defined
# by f13 which in linear in z. Then
#
#      g(x,y) = 0 and f(x,y,z)=0
#
# define two functions x(z) and y(z). Procedure zfixed
# computes x(z) and y(z) for a fixed z, given a initial
# guess x and y.
#
#                                        Ren-Cang Li, June 1, 1996
#                                        na.rcli@na-net.ornl.gov

zfixed:=proc(x0,y0,z0,x1,y1)
           local A1, B1, xi0, yi0, xi1, yi1, eps, niter;
           eps:=10^(-Digits+20):
	   xi0:=x0: yi0:=y0: 
           A1:=matrix(2,2,[subs(x=xi0,y=yi0,xfxyh),
			   subs(x=xi0,y=yi0,yfxyh),
                           subs(x=xi0,y=yi0,z=z0,xf13h),
                           subs(x=xi0,y=yi0,z=z0,yf13h)]):
           B1:=linsolve(A1,vector([subs(x=xi0,y=yi0,fxyh),
				   subs(x=xi0,y=yi0,z=z0,f13h)])):
           xi1:=xi0-B1[1]: yi1:=yi0-B1[2]:

           niter:=1:
           while ( abs(xi1-xi0)>eps*abs(xi1) or abs(yi1-yi0)>eps*abs(yi1) ) 
		  and niter < 101 do
                  niter:=niter+1;
                  xi0:=xi1: yi0:=yi1:
                  A1:=matrix(2,2,[subs(x=xi0,y=yi0,xfxyh),
                                  subs(x=xi0,y=yi0,yfxyh),
                                  subs(x=xi0,y=yi0,z=z0,xf13h),
                                  subs(x=xi0,y=yi0,z=z0,yf13h)]):
                  B1:=linsolve(A1,vector([subs(x=xi0,y=yi0,fxyh),
              			          subs(x=xi0,y=yi0,z=z0,f13h)])):
                  xi1:=xi0-B1[1]: yi1:=yi0-B1[2]:
           od:
           if niter=101 or niter>101 then
              print(`over 100 iterations in zfixed`);
           fi;
	   x1:=xi1: y1:=yi1:
	   end:
