splitting lib.rs to matrix.rs.  Several new methods introduced and tests written for matrix.rs.