added matlab code for k, n