Algorithms with matrices