|
Further Examples: Total
Here is a list of numbers.
In[1]:= 
This gives the sum.
In[2]:= 
Out[2]= 
This does the same thing.
In[3]:= 
Out[3]= 
The head need not be Plus.
In[4]:= 
Out[4]= 
Here is a nested list.
In[5]:= 
This gives the sum of the elements of .
In[6]:= 
Out[6]= 
Here is a list of million pseudorandom real numbers between and .
In[7]:= 
Total is much faster than Plus in summing the elements of ..
In[8]:= 
Out[8]= 
In[9]:= 
Out[9]= 
Total also gives the sum of symbolic lists.
In[10]:= 
Out[10]= 
In[11]:= 
Out[11]= 
In[12]:= 
Out[12]= 
In[13]:= 
Out[13]= 
Here is an expression.
In[14]:= 
Here Total sums all expressions with head equal to .
In[15]:= 
Out[15]= 
In[16]:= 
Out[16]= 
Here is a list of two matrices.
In[17]:= 
Out[17]= 
This adds the matrices.
In[18]:= 
Out[18]//MatrixForm= 
This adds the rows of the sum of the matrices.
In[19]:= 
Out[19]//MatrixForm= 
This adds all the elements of the matrices.
In[20]:= 
Out[20]= 
This gives the precision of a machine number on any given computer, whether 16-bit, 32-bit, or 64-bit.
In[21]:= 
Out[21]= 
Here is a list of numbers.
In[22]:= 
Out[22]= 
Neither Plus nor Total register the sum of the small numbers in .
In[23]:= 
Out[23]//FullForm= 
In[24]:= 
Out[24]//FullForm= 
Using the option Total gives a result closer to the true sum.
In[25]:= 
Out[25]//FullForm= 
In[26]:= 
Out[26]//FullForm= 
|