MathGroup Archive 2000

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

Search the Archive

Re: Sequence of functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24084] Re: Sequence of functions
  • From: "Souvik Banerjee" <s-banerjee at nwu.edu>
  • Date: Fri, 23 Jun 2000 02:26:51 -0400 (EDT)
  • Organization: Northwestern University, Evanston, IL, US
  • References: <8is7i9$h45@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I got around this problem by using = instead of := for both the function
definition and using local variable for the second function definition. that
is:

 Fx[ft_] := Block[ {g, h},
     Do[
       g[i][t_] = Sum[h[j][t], {j, i - 1}];
       Plot[g[i][t], {t, 0, 4}];
       h[i][t_] = With[{ii=i},  g[ii][t]];
       Plot[h[i][t], {t, 0, 4}],
       {i, 1, 3}]
     ]

Wondering whether this is the recommended way or is there something
fundamental I am missing.

-Souvik


Souvik Banerjee <s-banerjee at nwu.edu> wrote in message
news:8is7i9$h45 at smc.vnet.net...
> Dear MathGroup Members,
>
> I am having a problem with defining a sequence of functions. A highly
> simplified version of the problem is given below:
>
> Suppose I define a function as follows, where the argument B is another
> function and ls is a list of numbers:
>
> Fx[ft_] := Block[ {g, h},
>     Do[
>       g[i][t_] := Sum[h[j][t], {j, i - 1}]; (* usually a more complicated
> function of h[j][t], j=1,...,i-1 here *)
>       Plot[g[i][t], {t, 0, 4}];
>       h[i][t_] := g[i][t]; (* usually a more complicated function of
g[i][t]
> here *)
>       Plot[h[i][t], {t, 0, 4}],
>       {i, 1, 3}]
>     ]
>
> and then suppose we call Fx as
> Fx[{1, 2, 3}]
>
> Then at the beginning of the second iteration it says that the recursion
> depth is exceeded. I believe that this is happening because when it tries
to
> evaluate g[2][t] it looks for h[1][t], but now h[1][t] is getting
(wrongly)
> defined in terms of the current i (= 2) and hence goes into the recursion.
>
> How to get around this problem?
>
> Thanks,
>
> -Souvik
>
>
>




  • Prev by Date: Re: RE:Working Precision
  • Next by Date: "misbehaving" Union function
  • Previous by thread: Re: Sequence of functions
  • Next by thread: Mean of Geometric and Negative Binomial distributions