Code is now returning a matrix R.

Matrix R used to be returned pretty much filled with NaN's. This was due
to an error in the max_offdiagonal-function, where the code said
l = i;
k = l;.
By changing it to
l = i;
k = j;
matrix R is now actually filled with numbers now it remains to see
whether the output looks reasonable.