function yi = interp_Herm(x,y,yp,xi)
% This function uses Hermite interpolation to generate the vector yi at xi 
% given the values y and the first derivatives yp at the nodes x.

ind_x_ant = 1;
x_ant = x(ind_x_ant);
for j = 1:length(xi)
    % Find adjacent node before x(i)
    while x(ind_x_ant+1) < xi(j)
        ind_x_ant = ind_x_ant + 1;
    end
    x_ant = x(ind_x_ant);
    x_aft = x(ind_x_ant+1);
    
    yp_n_ant = yp(ind_x_ant)*(x_aft-x_ant);
    yp_n_aft = yp(ind_x_ant+1)*(x_aft-x_ant);
    
    % Computing the value of the function at xi
    tau = (xi(j)-x_ant)/(x_aft-x_ant);
    
    yi(j) = (2*tau^3-3*tau^2+1)*y(ind_x_ant) + (tau^3-2*tau^2+tau)*yp_n_ant + ...
            (-2*tau^3+3*tau^2)*y(ind_x_ant+1) + (tau^3-tau^2)*yp_n_aft;
end
    