format long
f=@(x) tan(x/4)-1;
df1=@(x) sec(x/4)^2/4; 
Nmax=10; 
tol=1e-10;

x=3; %initial guess
res=zeros(Nmax,1); 

for i=1:Nmax 
    xnew=x-f(x)/df1(x);%Newton Iteration
    res(i)=abs(f(xnew)); %Residual
    if(abs(xnew-x)<tol) %Check Tolerance to Stop
        break;
    end
    x=xnew;
end 
err=abs(x-pi)  %compute error
semilogy(1:i,res(1:i),'o-'); %plot solutions
 
