%
% File name: newton.m 
%      Date: March 05, 2017      
%
clc 
clear all 
format long
%
%
%
p0        = pi/4; 
M         = 100;
delta     = 10^(-12);
epsilon   = 10^(-12);
v         = cos(p0) - p0; 
[0, p0, v] 
%
%
%
if abs(v) < epsilon  
    display('We obtain the approximate solution')
    [0, p0, v]  
    return 
end    
for k=1:1:M
    p1 = p0 - v/(- sin(p0)-1);
    v   = cos(p1) - p1;
    [k, p1, v]
    if abs(p1-p0) < delta || abs(v) < epsilon
        display('We obtain the approximate solution')  
        [k, p1, v]
        return 
    else
        p0 = p1;         
    end
end