# Fxy defines a polynomial g(x,y) with 754 terms. Think of
# g(x,y) = 0 defines a function x(y). And now we want to
# find the x and y such that x'(y)=0. This is amount to solve
# the following system of equations:
#
#           g(x,y)=0 and g (x,y)=0.
#                         y
# The following short MAPLE code calls OneStep(x0,y0,x1,y1)
# to find a critical point, given a decent initial guess. 
#
#                                        Ren-Cang Li, June 1, 1996
#                                        na.rcli@na-net.ornl.gov

GetCritPt:=proc(x0,y0,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,xyfxyh),
                           subs(x=xi0,y=yi0,yyfxyh)]):
           B1:=linsolve(A1,vector([subs(x=xi0,y=yi0,fxyh),
				   subs(x=xi0,y=yi0,yfxyh)])):
           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,xyfxyh),
                                  subs(x=xi0,y=yi0,yyfxyh)]):
                  B1:=linsolve(A1,vector([subs(x=xi0,y=yi0,fxyh),
              			          subs(x=xi0,y=yi0,yfxyh)])):
                  xi1:=xi0-B1[1]: yi1:=yi0-B1[2]:
           od:
           if niter=101 or niter>101 then
              print(`over 100 iterations in GetCritPt`);
           fi;
	   x1:=xi1: y1:=yi1:
	   end:
