﻿disp("Exercise 1");
function coefficients = nevilleCoefficients(x, y)
    % x is the vector of x-values
    % y is the vector of y-values (initial coefficients for degree 0 polynomials)
    
    n = length(x);
    P = cell(n, n);  % Initialize a cell array to store polynomial coefficients

    % Initializing degree 0 polynomials
    for i = 1:n
        P{i, 1} = [y(i)];  % Polynomial of degree 0 (constant) with coefficient y(i)
    end

    % Iteratively compute coefficients for higher degree polynomials
    for j = 2:n  % Degree of polynomial
        for i = 1:(n-j+1)
            % Calculate coefficients of P{i,j} based on P{i+1,j-1} and P{i,j-1}
            % This step involves algebraic manipulation and polynomial arithmetic
            % to adapt Neville's recursion formula to coefficient computation.
            P{i, j} = ...  % Compute and store coefficients here
        end
    end
 % Final coefficients of the polynomial Nn
    coefficients = P{1, n};
end
