       Re: Table[ ...If[...i...] ,{i,...}]

• To: mathgroup at yoda.physics.unc.edu
• Subject: Re: Table[ ...If[...i...] ,{i,...}]
• From: David Withoff <withoff>
• Date: Fri, 17 Jul 1992 10:21:33 -0500

```> Hi mathgroup,
>  why is the i in
>
>  Table[ v[i]'[t] == If[ x[i]>0,ex1,ex2] , {i,2,6} ]
>
>  not replaced with the iterator i?
>   thanks
>
>   michael trott
>
>   trott at physik.th-ilmenau.de

The Table function works by sequentially assigning values to the
iteration parameter, evaluating the first argument, and using the
result to fill in the table.  In the above example it constructs
a list with five elements:

In:= result = {Null, Null, Null, Null, Null}

assigns a value to i:

In:= i = 2

evaluates the first argument:

In:= v[i]'[t] == If[ x[i]>0,ex1,ex2]

Out= (v)'[t] == If[x[i] > 0, ex1, ex2]

fills in the first entry of the table:

In:= result[] = %

and repeats the process to obtain:

Out= {(v)'[t] == If[x[i] > 0, ex1, ex2],

>    (v)'[t] == If[x[i] > 0, ex1, ex2],

>    (v)'[t] == If[x[i] > 0, ex1, ex2],

>    (v)'[t] == If[x[i] > 0, ex1, ex2],

>    (v)'[t] == If[x[i] > 0, ex1, ex2]}

This result is a consequence, among other things, of If having
attribute HoldAll.  One way to change this behavior is to use
Evaluate:

In:= Table[v[i]'[t] == If[ Evaluate[x[i]>0],ex1,ex2], {i, 2, 6}]

Out= {(v)'[t] == If[x > 0, ex1, ex2],

>    (v)'[t] == If[x > 0, ex1, ex2],

>    (v)'[t] == If[x > 0, ex1, ex2],

>    (v)'[t] == If[x > 0, ex1, ex2],

>    (v)'[t] == If[x > 0, ex1, ex2]}

(For additional information, refer to page 730 of the book.)

Dave Withoff
withoff at wri.com

```

• Prev by Date: Re-indexing Mathematica
• Next by Date: Re: Table[ ...If[...i...] ,{i,...}]
• Previous by thread: Re: Table[ ...If[...i...] ,{i,...}]
• Next by thread: Re: Table[ ...If[...i...] ,{i,...}]