
%
% Execute code and read and follow instructions at end:
%
% Here we will plot the sequential tangent lines that 
% generate the sequence of approximations x(n) of the
% root of f(x). Here we'll use
%
%          f(x) = x^2-0.5
%
% Initial guess for Newton's method:
%
x(1)=2;
%
% Perform m=3 Newton iterates
%
m=3;
for i=1:m
    x(i+1)=x(i)-f(x(i))./df(x(i));
end;
%
% For plotting later first compute (X,Y)=(X,f(X))
% for some range of X. "zero" is a vector of zeros
% the same length as X. So for instance you can
% plot X versus "zero" later.
%
%X=-4:0.01:4;
X=-6:0.01:6;
Y=f(X);
zero=0*X;
n=length(X);
%
%  The x(i+1) iterate is given as the point where
%  the tangent line at x(i) intersects the y=0 axis.
%  The i-th tangent line has eqn:
%
%         y = f(x(i)) + f'(x(i))*(x-x(i)) = L_i(x)
%  
%  Below we make a matrix L(m,n)initially of zeros
%  whos i-th row will be L_i(x) above. That row on 
%  its own is L(i,:)    --- syntax wise in matlab.
%
L=zeros(m,n);
for i=1:m
   L(i,:)=f(x(i))+df(x(i))*(X-x(i));
end
%
%
%--------------------------------------------------------------
%
% PROJECT FOUR : Modify so the first three tangent lines
%                are plotted. 
%
%                Include x,y label names and a title.
%
%                Print your figure.
%                
plot(X,Y,X,zero,X,L(1,:),X,L(2,:),X,L(3,:))
%ylim([-5,4]);
%
%
%--------------------------------------------------------------
%
% PROJECT FIVE : Repeat project four above for
%
%                     f(x) =arctan(beta*x)      beta=0.695
%
%                In Matlab the arctan function is denoted:
%
%                  >> y = atan(x)
%
%                where x is a vector. Be sure to recode f'(x).
%
%                Use x(1)=2 for the first guess.
%
%                Is it converging?
%
%                Print your figure.
%                
%          

