change size working in to reduce and to expand

With this version the matrix can be resized to any dimensions. Created
two input range to make easy the tests.