MathGroup Archive 2005

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

Search the Archive

Re: "Alternating" function

On Tuesday, December 20, 2005 at 23:35 GMT -0500, Renan wrote:

> I've tried using Nest but I don't find how to keep switching between
> Plus and Minus: I would need something that would return an "index" so
> I could keep track of when I need to "switch" the operation. (e.g. if
> the "index" is odd, the operation is "Plus", otherwise is "Minus")

You could define a dummy index variable at the beginning of your cell
(eg. i=1;). Then in your function, simply add the factor ((-1)^i++).
That way i is incremented every time the function is applied.

  • Prev by Date: Returning an empty sequence
  • Next by Date: Re: NDSolve
  • Previous by thread: Re: "Alternating" function
  • Next by thread: Re: "Alternating" function