Matrix multiplication algorithm