Fix issue 935: error in matrix calculation

This should fix the problem found in issue #935