%-----------newton.m----------------------
function x1 = newton(a,epsilon)
% Newton-Raphson algorithm
x0=a; 
x1 = x0-f(x0)/df(x0)
counter = 1;
while abs(x1-x0) > epsilon
    x0 = x1;
    x1 = x0-f(x0)/df(x0)
    counter = counter+1;
    if counter > 20 
       error('Newton method failed to converge')
    end
end

%-----------f.m----------------------

function z = f(theta)
% projectile problem, g=1, v0=1, d=0.5
%z = 2*cos(theta).*sin(theta)-0.5;

% RNH problem
z=cos(theta)-theta;

%-----------df.m----------------------

function z = df(theta)
% projectile problem, g=1, v0=1, d=0.5, df/dtheta
%z = 2*cos(2*theta);

% RNH problem
z=-sin(theta)-1;
