%
% File name: comparisonsecant.m
% Author: Suh-Yuh Yang at NCU
% Date: September 21, 2018  
%
clear all;
format long 
M         = 100;
delta     = 10^(-10);
epsilon = 10^(-10);
h          = 10^(-7); 
x0        = 2.0; 
v          = (x0)^2- 1.0; 
x1         = x0 - v/((((x0+h)^2-1.0)-((x0)^2-1.0))/h);
w          = (x1)^2 - 1.0; 
[1, x1, w]
%
%
%
if abs(w) < epsilon  
    display('The approximate is obtained')
    x1 
    break
end    
for k=2:1:M
    derivative = (w-v)/(x1- x0);
    x0 = x1;
    v = (x0)^2- 1.0; 
    x1 = x1 - w/derivative;
    w   = (x1)^2 - 1.0;
    [k, x1, w]
    if abs(x1-x0) < delta | abs(w) < epsilon
        display('The approximate solution is obtained')  
        [k, x1, w]
        break     
    end
end
