matrix manipulation in erlang