Message Boards Message Boards

0
|
4916 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

What is the syntax for finding the log of every element in a list?

I have a list defined as a={1,2,3,4,5} I want to find the log of this. How can I do it?

POSTED BY: Aanandita Katre

if you type ?? on name of any command, Mathematica will tell you its properties. Look for Listable. If it is there, this means you can pass a list to the function, and it will act on the whole list.

?? Log
Attributes[Log] = {Listable, NumericFunction, Protected}

Since Log is listable, then just do

 a = {1, 2, 3, 4, 5};
 Log[a]
 (*{0, Log[2], Log[3], Log[4], Log[5]}*)

If the command is not listable, you can always map the function on the list, like this

Log[#] & /@ a
POSTED BY: Nasser M. Abbasi
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