function newx = collatz(x) % if (rem(x,2)==1) newx = 3*x+1; else newx = x/2; end;