# Vectors and Matrices

Vectors and matrices in the Wolfram Language are simply represented by lists and by lists of lists, respectively.

 {a,b,c} vector {{a,b},{c,d}} matrix The representation of vectors and matrices by lists.

This is a 2×2 matrix:
 In:= Out= Here is the first row:
 In:= Out= Here is the element :
 In:= Out= This is a twocomponent vector:
 In:= Out= The objects p and q are treated as scalars:
 In:= Out= Vectors are added component by component:
 In:= Out= This gives the dot (scalar) product of two vectors:
 In:= Out= You can also multiply a matrix by a vector:
 In:= Out= Or a matrix by a matrix:
 In:= Out= Or a vector by a matrix:
 In:= Out= This combination makes a scalar:
 In:= Out= Because of the way the Wolfram Language 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 i=1,2,…,n Array[a,n] build a length‐n vector of the form {a,a,…} Range[n] create the list {1,2,3,…,n} Range[n1,n2] create the list {n1,n1+1,…,n2} Range[n1,n2,dn] create the list {n1,n1+dn,…,n2} 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 a×b) Norm[v] Euclidean norm of a vector

Functions for vectors.

 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 i,j element a[i,j] 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 i,j element in the matrix list Dimensions[list] give the dimensions of a matrix represented by list

Functions for matrices.

 Column[list] display the elements of list in a column MatrixForm[list] display list in matrix form

Formatting constructs for vectors and matrices.

This builds a 3×3 matrix with elements :
 In:= Out= This displays s in standard twodimensional matrix format:
 In:= Out//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:= Out= 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:= Out= Here are the dimensions of the matrix on the previous line:
 In:= Out= This generates a 3×3 diagonal matrix:
 In:= Out= 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.

Here is the 2×2 matrix of symbolic variables that was defined:
 In:= Out= This gives its determinant:
 In:= Out= Here is the transpose of m:
 In:= Out= This gives the inverse of m in symbolic form:
 In:= Out= Here is a 3×3 rational matrix:
 In:= Out= This gives its inverse:
 In:= Out= Taking the dot product of the inverse with the original matrix gives the identity matrix:
 In:= Out= Here is a 3×3 matrix:
 In:= Out= Eigenvalues gives the eigenvalues of the matrix:
 In:= Out= This gives a numerical approximation to the matrix:
 In:= Out= Here are numerical approximations to the eigenvalues:
 In:= Out= "Linear Algebra in Mathematica" discusses many other matrix operations that are built into the Wolfram Language.