Message Boards Message Boards

0
|
3720 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Evaluating a function over an input range & putting output into list?

Posted 3 years ago

Hello everyone,

I am trying to evaluate a function over a range of input parameters and put each output into a common list. For instance, if we have a function f(a) = Exp[-a]*1000, I am hoping to evaluate the function over the range [0,1] and compile a list of outputs, i.e., something like {f(0),f(0.001), f(0.002),...}. Attached is a notebook showing the function I am trying to map to a list and my attempt to solve the problem using a For loop.

Alex

Attachments:
POSTED BY: Alex L
2 Replies
Posted 3 years ago

If you need the input and output

(* As a List of pairs *)
Map[{#, 1000 Exp[-#]} &, Range[0, 1, .01]]

(* As an Association *)
AssociationMap[1000 Exp[-#] &, Range[0, 1, .01]]
POSTED BY: Rohit Namjoshi

Hello Alex, A bunch of choices:

Caliing Exp on a list:

1000 Exp[Range[0, 1, .01]]

Using table with an iterator

Table[1000 Exp[-v], {v, 0, 1, .01}]

Iterating over a list

With[{values = Table[x, {x, 0, 1, .01}]},
 1000 Table[Exp[-v], {v, values}]
 ]

Mapping a pure function:

1000 Exp[-#] & /@ Range[0, 1, .01]

aka

Map[1000 Exp[-#] &, Range[0, 1, .01]]

and many many others.

POSTED BY: W. Craig Carter
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract