You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: newton_secant_steffensen.m
    path of file: ./repos/numerical-methods/Newton_Secant_Steffensen
    
    the code of the file until where you have to start completion: %% Newton's Method for Exercises 2.1: 5,9,11,13

% Name: Shayne O'Brien
% Course: MATH 345 (Dr. Haddad)
% Date: 9/25/16
% Content: Function to compute 

%% Background
%Inverses of numbers without divison: In the early days of computing,
% calculator
    
function g       
    else % Otherwise, since a fixed point was not found within a reasonable TOL level:
        fprintf('Newtons Method failed to find an acceptably accurate root within N=%d iterations.\n', N) % display error
    end % end if loop
end % end if loop


%% Part (d)
%Modify your code for Newton's Method to apply the Secant Method to your
% function from Part (b) with a = 21. You may create a completely new
% script or m-file to do this, or place it in a new cell following Newton's
% Method.

% Begin Part (d)

% Note: We use a new function here, rather than the one derived in Part
% (b). I could not get the code to work using the function from Part (b),
% but using this new f(x) we do correctly obtain the root.

% Input a, f(x)
a = input('Input the number for which we will find the inverse: '); % Input a. We are trying to find 1/a.
f = @(x)( (a*x) - 1 ); % Input function, f(x) = a*x - 1 = 0

% Ask user for input
N = input('Input maximum number of iterates, N: '); % ask user to put in max. number of iterates, N
pvec = zeros(N,1); % pre-allocate vector to store each p approximation
pvec(1) = input('Input initial approximation, Po: '); % ask user to input initial guess, P0
pvec(2) = input('Input initial approximation, P1: '); % ask user to input initial guess P1
TOL = input('Input tolerance level, TOL: '); % ask user to input tolerance, TOL

% Pre-allocations to speed up our algorithm
IterationVec = zeros(N,1); % pre-allocate vector to store iterations for speed
AbsCauchyError = zeros(N,1); % pre-allocate vector to store absolute Cauchy error for speed
RelCauchyError = zeros(N,1); % pre-allocate vector to store relative Cauchy error for speed

% Fixing pre-allocated vectors for table output
RelCauchyError(1:2) = NaN; % first two entries are NaN because error cannot be computed in the 1st/2nd iteration.
AbsCauchyError(1:2) = NaN; % first two entries are NaN because error cannot be computed in the 1st/2nd iteration.
IterationVec(1) = 1; % Let the first entry of the iteration vector be 1, since we will start at i=2.
% Initialize k for final output
k = 0; % k is a constant that we will use to simplify the decision making process for our output.
       % if k remains 0 after N iterations, we have not found a fixed point
       % within acceptable TOL. If k = 1, we have and will therefore
       % display all relevant results.

% Initialize i
i = 2; % let i = 2. i will be used as the check for the while loop. We start at i=2 
       % because the secant method computes Pn = Pn-1 - f(Pn-1)(Pn-1 - Pn-2)/((f(Pn-1) - f(Pn-2)))
       % so if we let i = 1, the script would print an error.

% Error catching
if ((N < 1) || (mod(N,1) ~= 0)) % If the max number of iterations N has been set below 1 or N is not an integer:
    disp('Error: Maximum number of iterations must be an integer greater than equal to 1.') % display error.
elseif TOL <= 0 % Otherwise, if the tolerance is negative:
    disp('Error: TOL must be positive.') % display error.
elseif (f(pvec(1)) * f(pvec(2)) > 0 ) % If there is no sign change for f(Po)*f(P1):
    disp('Error: f(Po) * f(P1) > 0. Try different intiial approximations that will give a sign change.') % display error; likely that Secant Method won't converge.
else % otherwise since both criteria are met, proceed with computation.
    
    % Implementation of Newton's Method
    while i < N % Until we reach our max number of iterations N:
        p = pvec(i) - (f(pvec(i))*(pvec(i) - pvec(i-1)))/(f(pvec(i))-f(pvec(i-1))); % compute p-sub-i
                             % Pn = Pn-1 - f(Pn-1)(Pn-1 - Pn-2)/((f(Pn-1) - f(Pn-2)))
        IterationVec(i) = i; % update Iteration vector for i-th entry.
        AbsCauchyError(i) = abs(p - pvec(i)); % update relative Cauchy error vector. index is i+1 because error cannot be computed in the first iteration.
        RelCauchyError(i) = abs((p - pvec(i))/p); % update absolute Cauchy error vector. index is i+1 because error cannot be computed in the first iteration.
        if ( abs((p - pvec(i))) ) < TOL % If the absolute Cauchy error is less than TOL we have found a fixed point so:
            pvec = pvec(1:i); % shorten vector so table outputs correctly
            IterationVec = IterationVec(1:i); % shorten vector
            AbsCauchyError = AbsCauchyError(1:i); % shorten vector
            RelCauchyError = RelCauchyError(1:i); % shorten vector
            k = 1; % set k = 1 so the root will be printed
            break % break while loop
        else % Otherwise:
            i = i + 1; % increment i by 1
            pvec(i) = p; % store the i-th iteration of p
        end