Skip to content

Instantly share code, notes, and snippets.

@meysampg
Created August 7, 2015 18:13
Show Gist options
  • Save meysampg/229b40d2cbb51f84b331 to your computer and use it in GitHub Desktop.
Save meysampg/229b40d2cbb51f84b331 to your computer and use it in GitHub Desktop.
function result = indToBernstienInd(d, k)
% Convert ordinary order to lexicographical order.
% Input:
% @d: integer, dimension of spline space.
% @k: integer, position on ordinary sequence order
% Output:
% @result: vector[3], position of k on exicography order
result = zeros(1,3);
delt = @(k) ceil((-3 + sqrt(9+8*(k-1)))/2);
result(1) = d - delt(k);
result(3) = k - ((d-result(1)+1)*(d-result(1)))/2 - 1;
result(2) = d - result(1) - result(3);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment