Question: Use Newton's Method to Find Local Extrema

Use Newton's Method to find a local extrema for f(x)=sin(x^2)+x

with start point x=(1,0)

take derivative of f(x) then apply Newton's Method

 

My teacher started us off with this but I can't seem to get it to work the way she did, any help would be appreciated!

 

prcNewton:=proc( ) 

  local ftn,strpt,epsilon,maxlps,i,xn,dftn; 

  if nargs>4 then     

     error "expecting four arguements at most"; 

  elif nargs< 2 then     

     error "expecting two arguements at least"; 

  end if;

   

  ftn:=arg[1]; 

  srtpt:=args[2];   

 

  if nargs=2 then     

    epsilon:=10^(-7);    

    maxlps:=1000; 

  elif nargs=3 then    

    epsilon:=args[3];    

    maxlps:=1000; 

  else    

    epsilon:=args[3];   

    maxlps:=args[4]; 

  end if;   

 

  dftn:=D(ftn); 

  xn:=strpt; 

  i:=0;

   

while abs(evalf(ftn(xn)))>epsilon do 

if abs(evalf(dftn(xn)))<epsilon then 

print('please change another starting point');   

 

break; 

end if;   

 

xn:=evalf(xn-(ftn(xn))/(dftn(xn))); 

i:=i+1; 

if i>maxlps then 

error solution 'not' found;   

 

end if;   

 

end do; 

return xn; 

end proc:   

Please Wait...