(*) Function matdist added; calculating the "distance" between matrixes
is necessary as a criteria for self consitent calculations.