gusucode.com > matlab通信工程仿真源码(张德丰等编著)程序书籍 > matlab_code/matlab通信工程仿真源码(张德丰等编著)/第3章/collatz.m
function c = collatz(n) % collatz % classic “3n+1” problem from number theory c = n; while n >1 if rem(n,2) == 0 n = n/2; else n = 3*n+1; end c = [c,n]; end