Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: Multiple nests?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81823] Re: [mg81764] Multiple nests?
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Thu, 4 Oct 2007 04:25:14 -0400 (EDT)
  • References: <28217545.1191409498099.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

Here's a simple method:

Clear[doubleNest]
doubleNest[{f_, n_Integer}, list_] := Nest[f, list, n]
doubleNest[{first_}, list_] := doubleNest[first, list]
doubleNest[{first_, others__}, list_] :=
  doubleNest[{others}, doubleNest[first, list]]

functions = {{Exp, 2}, {dum, 4}, {Sqrt, 3}, {Log, 2}, {#^2 &, 5}}
list = Range@3

{{Exp, 2}, {dum, 4}, {Sqrt, 3}, {Log, 2}, {#1^2 &, 5}}

{1, 2, 3}

doubleNest[functions, list]

Log[Log[dum[
    dum[dum[dum[{\[ExponentialE]^\[ExponentialE], \[ExponentialE]^\
\[ExponentialE]^2, \[ExponentialE]^\[ExponentialE]^3}]]]]^(1/8)]]^32

"list" doesn't have to be a List, by the way... depending on the  
functions, of course.

Bobby

On Wed, 03 Oct 2007 01:27:50 -0500, Anolethron <Humbleguy876 at hotmail.com>  
wrote:

> I'm using Mathematica 5.2 and i need to apply a function to a list
> several times. I'm using next for doing it once, but after this process
> i need to apply a different function to the result of the previous one,
> as in this naif example:
>
> no1[n_]:=Nest[function,list,n]	
> no2[m_]:=Nest[function2,result of the previous one,m]
> no3[l_]:=Nest[function3,resultofthepreviousone,l]
>
> Is there a command or a way to do this straight away?
>
> Thanks in advance
>
>



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: Manipulate+Plot showing no output
  • Next by Date: Re: Converting Mathematica into c++ code
  • Previous by thread: Re: Multiple nests?
  • Next by thread: Re: Multiple nests?