MATHEMATICA TUTORIAL

# Vectors and Matrices

Vectors and matrices in *Mathematica* are simply represented by lists and by lists of lists, respectively.

The representation of vectors and matrices by lists.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]= |

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

In[9]:= |

Out[9]= |

In[10]:= |

Out[10]= |

In[11]:= |

Out[11]= |

Because of the way *Mathematica* uses lists to represent vectors and matrices, you never have to distinguish between "row" and "column" vectors.

Table[f,{i,n}] | build a length-n vector by evaluating f with |

Array[a,n] | build a length-n vector of the form |

Range[n] | create the list |

Range[n_{1},n_{2}] | create the list |

Range[n_{1},n_{2},dn] | create the list |

list[[i]] or Part[list,i] | give the i element in the vector list |

Length[list] | give the number of elements in list |

c v | multiply a vector by a scalar |

a.b | dot product of two vectors |

Cross[a,b] | cross product of two vectors (also input as ) |

Norm[v] | Euclidean norm of a vector |

Table[f,{i,m},{j,n}] | build an m×n matrix by evaluating f with i ranging from 1 to m and j ranging from 1 to n |

Array[a,{m,n}] | build an m×n matrix with element |

IdentityMatrix[n] | generate an n×n identity matrix |

DiagonalMatrix[list] | generate a square matrix with the elements in list on the main diagonal |

list[[i]] or Part[list,i] | give the i row in the matrix list |

list[[All,j]] or Part[list,All,j] | give the j column in the matrix list |

list[[i,j]] or Part[list,i,j] | give the element in the matrix list |

Dimensions[list] | give the dimensions of a matrix represented by list |

Column[list] | display the elements of list in a column |

MatrixForm[list] | display list in matrix form |

Formatting constructs for vectors and matrices.

In[12]:= |

Out[12]= |

In[13]:= |

Out[13]//MatrixForm= | |

This gives a vector with symbolic elements. You can use this in deriving general formulas that are valid with any choice of vector components.

In[14]:= |

Out[14]= |

This gives a 3×2 matrix with symbolic elements. "Building Lists from Functions" discusses how you can produce other kinds of elements with Array.

In[15]:= |

Out[15]= |

In[16]:= |

Out[16]= |

In[17]:= |

Out[17]= |

c m | multiply a matrix by a scalar |

a.b | dot product of two matrices |

Inverse[m] | matrix inverse |

MatrixPower[m,n] | n power of a matrix |

Det[m] | determinant |

Tr[m] | trace |

Transpose[m] | transpose |

Eigenvalues[m] | eigenvalues |

Eigenvectors[m] | eigenvectors |

Some mathematical operations on matrices.

In[18]:= |

Out[18]= |

In[19]:= |

Out[19]= |

In[20]:= |

Out[20]= |

In[21]:= |

Out[21]= |

In[22]:= |

Out[22]= |

In[23]:= |

Out[23]= |

In[24]:= |

Out[24]= |

In[25]:= |

Out[25]= |

Eigenvalues gives the eigenvalues of the matrix.

In[26]:= |

Out[26]= |

In[27]:= |

Out[27]= |

In[28]:= |

Out[28]= |

"Linear Algebra in *Mathematica*" discusses many other matrix operations that are built into *Mathematica*.