

   %                     script file newton2.m   
   %  User first creates inline functions for f(x,y), g(x,y)  or
   %  mfiles for f(x,y) and g(x,y).
   % Script will ask user to enter the starting value 
   % as a column vector.  Does 5 iterations. 

     p = input('enter the starting value as a col. vector   ')


     syms x y ;
     ff = sym(f(x,y));
     gg = sym(g(x,y));


     ffx = diff(ff,x);
     ffy = diff(ff,y);

     ggx = diff(gg,x);
     ggy = diff(gg,y);

     fx = inline(vectorize(ffx), 'x', 'y')
     fy = inline(vectorize(ffy), 'x', 'y')
     gx = inline(vectorize(ggx), 'x', 'y')
     gy = inline(vectorize(ggy), 'x', 'y')

     disp(' ')
     disp(' iterate      p       error (Newton step)   ')
     format compact
     format long
     for n = 1:5
        J = [fx(p(1),p(2)) fy(p(1),p(2)); gx(p(1),p(2)) gy(p(1),p(2))];
        F = [f(p(1),p(2)); g(p(1),p(2))];
        s = -J\F;
        p = p +s;
        n
        [p, s]
        disp(' ')
     end
     format loose
     format short




     
     
