MathGroup Archive 2013

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

Search the Archive

Re: very basic RecurrenceTable puzzle

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130714] Re: very basic RecurrenceTable puzzle
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Mon, 6 May 2013 02:25:33 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <20130504071941.9444A6A2F@smc.vnet.net>

I think of If as primarily a control construct rather than a numerical
function. I recommend that you use Piecewise for numerical functions.


RecurrenceTable[{st[t] == If[t < 2, st[t - 1], 1], st[-1] == 0}, st, {t,
-1,
  5}]


{0, st[-1], st[0], 1, 1, 1, 1}


RecurrenceTable[{st[t] == Piecewise[{{st[t - 1], t < 2}}, 1],
  st[-1] == 0}, st, {t, -1, 5}]


{0, 0, 0, 1, 1, 1, 1}


Attributes /@ {If, Piecewise}


{{HoldRest, Protected}, {HoldAll, Protected, ReadProtected}}


Note that If has attribute HoldRest rather than the HoldAll for Piecewise.



Bob Hanlon


On Sat, May 4, 2013 at 3:19 AM, Alan <alan.isaac at gmail.com> wrote:

> RecurrenceTable[{st[t] == If[t < 2, st[t - 1], 1], st[-1] == 0}, st, {t,
> -1, 5}]
>
> produces
>
> {0, st[-1], st[0], 1, 1, 1, 1}
>
> I'm not seeing why the output contains st[-1] and st[0] instead of 0s.
>
> Note that
> RecurrenceTable[{st[t] == st[t - 1], st[-1] == 0}, st, {t, -1, 5}]
> produces a list of zeros (i.e., no surprises).
>
> Thanks,
> Alan Isaac
>
>


  • Prev by Date: Re: Minimize Headscratcher
  • Next by Date: Re: (amusement) surprising result from PossibleZeroQ
  • Previous by thread: Re: very basic RecurrenceTable puzzle
  • Next by thread: Re: very basic RecurrenceTable puzzle