Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #14419 > unrolled thread
| Started by | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| First post | 2013-05-06 06:25 +0000 |
| Last post | 2013-05-06 06:25 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: very basic RecurrenceTable puzzle Bob Hanlon <hanlonr357@gmail.com> - 2013-05-06 06:25 +0000
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Date | 2013-05-06 06:25 +0000 |
| Subject | Re: very basic RecurrenceTable puzzle |
| Message-ID | <km7ibt$ibt$1@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@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
>
>
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web