
clear;

%......  invoke my own factorial function
%fak=lec12_factorial(8);
%fak
%fa2=2*3*4*5*6*7*8
%return;

%   demonstrate persistence
%lec12_persistent(0)
%lec12_persistent(3)
%lec12_persistent(7)
%return

% x=-1:0.01:1; y=lec12_F(x);  plot(x,y); grid('on');  %  P_5(x)
%    demonstrate function handles

%disp('start handles');

%F=@lec12_F
%DF=@lec12_DF

%[xx, mit]=N_R(F,DF,0.99,1.0e-4);  
%fprintf('result: zero at %f after %d iterations\n',xx,mit);return;

%%%%%%%%%%  simplest Newton Raphson, takes function handles
% global a
a=3

seta(5);
a

function seta(x)
global a
   a=x;
end

function [x nit]=N_R(ff,dff,xs,pr)
   xo=xs;  nit=0;
   while 1
       xn=xo-ff(xo)/dff(xo)
       nit=nit+1
       if abs(xn-xo) < pr; x=xn; return; end
       xo=xn
   end
end


