Re: very basic RecurrenceTable puzzle
- To: mathgroup at smc.vnet.net
- Subject: [mg130720] Re: very basic RecurrenceTable puzzle
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Mon, 6 May 2013 04:22:53 -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 don't know the internal workings of RecurrenceTable so I don't know how
the attribute affects its behavior, but I noted the difference in the
attributes and pointed it out. You could use If like this
Clear[st]
st[-1] = 0;
st[t_?NonNegative] := If[t < 2, st[t - 1], 1];
Table[st[t], {t, -1, 5}]
{0, 0, 0, 1, 1, 1, 1}
or with memory
Clear[st]
st[-1] = 0;
st[t_?NonNegative] :=
st[t] = If[t < 2, st[t - 1], 1];
Table[st[t], {t, -1, 5}]
{0, 0, 0, 1, 1, 1, 1}
Bob Hanlon
On Sat, May 4, 2013 at 4:28 PM, Alan G Isaac <alan.isaac at gmail.com> wrote:
> On 5/4/2013 8:01 AM, Bob Hanlon wrote:
>
>> Note that If has attribute HoldRest rather than the HoldAll for Piecewise.
>>
>
>
> First, thanks for the suggestion to use Piecewise.
>
> But ... should I have been able to deduce from that
> attribute difference the difference in the output?
> If so, might you add a word or two about that?
>
> Thanks,
> Alan Isaac
>
>
- References:
- very basic RecurrenceTable puzzle
- From: Alan <alan.isaac@gmail.com>
- very basic RecurrenceTable puzzle