Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > Defining Variables and Functions > Attributes >

Listable

Listable
is an attribute that can be assigned to a symbol f to indicate that the function f should automatically be threaded over lists that appear as its arguments.
  • Listable functions are effectively applied separately to each element in a list, or to corresponding elements in each list if there is more than one list.
  • All the arguments which are lists in a Listable function must be of the same length.  »
  • Arguments that are not lists are copied as many times as there are elements in the lists.
Log is listable:
Listable functions combine corresponding elements:
Arguments that are not lists are replicated as needed:
Log is listable:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
 
Listable functions combine corresponding elements:
In[1]:=
Click for copyable input
Out[1]=
 
Arguments that are not lists are replicated as needed:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
Define a function to be listable:
Most built-in mathematical functions are listable:
Listability works for any nesting depth of lists:
The nesting level of the different arguments need not be the same:
Listability works also with sparse arrays:
To apply a function to a vector, take advantage of Listable functions when possible:
Use the listability of Plus, Power, Sin and Times:
Use Map:
Use Table:
Use Table and Part to access elements of v as might be done in a lower-level language:
The results are the same up to numerical roundoff:
Use efficient sparse arithmetic to numerically solve the heat equation u_t=u_(x x):
Matrix for a second-order approximation to the second derivative on the grid x:
Incorporate Dirichlet boundary conditions to form the Jacobian J:
The sparse identity matrix:
Form sparse matrix m=I-h J for h=0.01` using the listability of arithmetic:
LU decomposition of m in a functional form:
Step initial condition on spatial grid x using the listability of UnitStep:
Get the solution at t=10, h=0.01 using the backward Euler method:
Listability is the same as automatic threading:
A function implemented in terms of a listable operation may not need the Listable attribute:
The system symbols with the Listable attribute:
Many of these are arithmetic or numerical functions:
The products given by Dot, Times, and KroneckerProduct are inner, element-wise, and outer:
The inner product of two vectors:
The vector resulting from the product of corresponding elements:
The matrix resulting from the outer product of the vectors:
All list arguments must have the same length:
New in 1
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team