function value = NthFunction(n,j,k)

% This function calculates the lexicographical ordering of the orthonormal
% polynomial of degree n, and index j and k.

Total = ((n+3)*(n+2)*(n+1))/6;
Deg1 = j+k;

for i= Deg1+1:n
    Total = Total - (i+1);
end

value = Total - j;

end % NthFunction