Vectors and Matrices

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

The representation of vectors and matrices by lists.

This is a 2×2 matrix:

m={{a,b},{c,d}}

Here is the first row:

m[[1]]

Here is the element (Subscript[m, 12]):

m[[1,2]]

This is a two-component vector:

v={x,y}

The objects p and q are treated as scalars:

p v+q

Vectors are added component by component:

v+{xp,yp}+{xpp,ypp}

This gives the dot (scalar) product of two vectors:

{x,y}.{xp,yp}

You can also multiply a matrix by a vector:

m.v

Or a matrix by a matrix:

m.m

Or a vector by a matrix:

v.m

This combination makes a scalar:

v.m.v

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

Functions for vectors.

Functions for matrices.

Formatting constructs for vectors and matrices.

This builds a 3×3 matrix s with elements (Subscript[s, ij])==i+j:

s=Table[i+j,{i,3},{j,3}]

This displays s in standard two-dimensional matrix format:

MatrixForm[s]

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

Array[a,4]

This gives a 3×2 matrix with symbolic elements. "Building Lists from Functions" discusses how you can produce other kinds of elements with (RefLink[Array, paclet:ref/Array]):

Array[p,{3,2}]

Here are the dimensions of the matrix on the previous line:

Dimensions[%]

This generates a 3×3 diagonal matrix:

DiagonalMatrix[{a,b,c}]

Some mathematical operations on matrices.

Here is the 2×2 matrix of symbolic variables that was defined:

m

This gives its determinant:

Det[m]

Here is the transpose of m:

Transpose[m]

This gives the inverse of m in symbolic form:

Inverse[m]

Here is a 3×3 rational matrix:

h=Table[1/(i+j-1),{i,3},{j,3}]

This gives its inverse:

Inverse[h]

Taking the dot product of the inverse with the original matrix gives the identity matrix:

%.h

Here is a 3×3 matrix:

r=Table[i+j+1,{i,3},{j,3}]

(RefLink[Eigenvalues, paclet:ref/Eigenvalues]) gives the eigenvalues of the matrix:

Eigenvalues[r]

This gives a numerical approximation to the matrix:

rn=N[r]

Here are numerical approximations to the eigenvalues:

Eigenvalues[rn]

"Linear Algebra in Mathematica" discusses many other matrix operations that are built into the Wolfram Language.