MathGroup Archive 2005

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

Search the Archive

Re: "Alternating" function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63269] Re: [mg63260] "Alternating" function
  • From: "Ingolf Dahl" <ingolf.dahl at telia.com>
  • Date: Thu, 22 Dec 2005 00:04:31 -0500 (EST)
  • Reply-to: <ingolf.dahl at telia.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Method 1)
Differentiate between odd and even numbers, and try the following:

g[f_, x_, n_Integer] := If[2*Floor[n/2] == n, Nest[(f[
    x + f[x - #]]) &, 0, n/2],
    (f[x - #]) &@  Nest[(f[x + f[x - #]]) &, 0, (n - 1)/2]]

Method 2)
With index:

g[f_, x_, n_Integer] := Module[{index}, index = 0; 
Nest[(f[x + (-1)^(index += 1)*#]) &, 0, n]]

With both methods, x + g[f, x, 5] gives your function.

Best regards

Ingolf Dahl
Sweden
http://web.telia.com/~u31815170/Mathematica/

-----Original Message-----
From: Renan [mailto:renan.birck at gmail.com] 
To: mathgroup at smc.vnet.net
Subject: [mg63269] [mg63260] "Alternating" function

Hello,

I want to make a "nested function" like: x + f[x - f[x + f[x - f[x +
f[x]]]]].

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")

How can I make this? I looked in the help but didn't find any informations.

Thanks.




--
Thanks/obrigado, Renan "Wishmaster" Birck - Canoas, Rio Grande do Sul,
Brasil
MSN: wizard_of_yendor at hotmail.com
Orkut: http://www.orkut.com/Profile.aspx?uid=2202360379963855296




  • Prev by Date: Re: "Alternating" function
  • Next by Date: Gaussian sums (Was: Speeding up simple Mathematica expressions?)
  • Previous by thread: Re: "Alternating" function
  • Next by thread: Re: Speeding up simple Mathematica expressions?