added a new version with a sparse matrix