[Date Index]
[Thread Index]
[Author Index]
Re: Evaluation Control
*To*: mathgroup at smc.vnet.net
*Subject*: [mg14877] Re: [mg14858] Evaluation Control
*From*: BobHanlon at aol.com
*Date*: Mon, 23 Nov 1998 10:11:55 -0500
*Sender*: owner-wri-mathgroup at wolfram.com
In a message dated 11/20/98 4:45:54 AM, phantomlord at my-dejanews.com
writes:
>I am writing a function which involves manipulation of lists, but have
>stumbled across a problem. It seems as though when I call
>"Print[list[i]]" in a Do[] loop (where i is the iterative variable) it
>returns the following: {0.,.2,.4,.6,.8,1.}[i] i.e. it hasn't referenced
>the one element I require for computation in the rest of the code.
>
>I try to evaluate a function f[x] at x=list[i], which returns:
>Cosh[{0.,.2,.4,.6,.8,1.}[i.]]+....bla bla bla so it seems that it
>interprets i as a decimal and NOT an integer, is this the cause of the
>problem or is there something else I am doing wrong?
>
Paul,
x = Table[Random[], {10}]
{0.390142,0.945503,0.585519,0.812327,0.0641894,0.728559,0.729633,0.516246,
0.652987,0.446624}
If the function is Listable, then just apply the function to the list
??Cosh
"Cosh[z] gives the hyperbolic cosine of z." Attributes[Cosh] =
{Listable, NumericFunction, Protected}
Cosh[x] == Cosh /@ x == Table[Cosh[x[[i]]], {i, 10}]
True
If the function is not Listable, then map it onto the list
f[x]
f[{0.390142,0.945503,0.585519,0.812327,0.0641894,0.728559,0.729633,0.516246,
0.652987,0.446624}]
f /@ x
{f[0.390142],f[0.945503],f[0.585519],f[0.812327],f[0.0641894],f[0.728559],
f[0.729633],f[0.516246],f[0.652987],f[0.446624]}
f /@ x == Table[f[x[[i]]], {i, 10}]
True
Bob Hanlon
Prev by Date:
**tab key**
Next by Date:
**Re: Sqrt and Listability**
Previous by thread:
**Re: Evaluation Control**
Next by thread:
**Re: Evaluation Control**
| |