MathGroup Archive 1991

[Date Index] [Thread Index] [Author Index]

Search the Archive

Mathematica Program

  • To: mathgroup at yoda.ncsa.uiuc.edu
  • Subject: Mathematica Program
  • From: pwm at macaw.jhuapl.edu (Phil W. Miller x8335 1-e138)
  • Date: Wed, 6 Mar 91 13:54:08 EST

Could someone please give me advice on good way of defining
the following iteration? (This is an example in the MATLAB manual)

	take any positive integer
	if it is even, divide by two; if it is odd multiply by 3 and add 1
        Repeat until your integer becomes 1

I  have defined the function f to be:
f[1] = 1
f[n_] := f[n/2] /; EvenQ[n]
f[n_] := f[3 n + 1] /; OddQ[n] && n != 1

which evaluates to 1 for a given integer.  What is a good way to
get the intermediate values used in the iteration so I can plot them?
I am a novice at programming in Mma, and would appreciate any help.

Thank you.

Phil Miller
pwm at macaw.jhuapl.edu


  • Prev by Date: Custom plot options
  • Next by Date: Mailing List Growth
  • Previous by thread: Custom plot options
  • Next by thread: Mailing List Growth