Vectors and Matrices
Vectors and matrices in Mathematica 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.
Here is the first row.
Here is the element .
This is a two-component vector.
The objects and are treated as scalars.
Vectors are added component by component.
This gives the dot (scalar) product of two vectors.
You can also multiply a matrix by a vector.
Or a matrix by a matrix.
Or a vector by a matrix.
This combination makes a scalar.
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[
n1,
n2]
create the list
Range[
n1,
n2,
dn]
create the list
list[[
i]]
or Part[
list,
i]
give the i^(th) 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
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 ^(th) element
DiagonalMatrix[
list]
generate a square matrix with the elements in list on the main diagonal
list[[
i]]
or Part[
list,
i]
give the i^(th) row in the matrix list
list[[
All,
j]]
or Part[
list,
All,
j]
give the j^(th) column in the matrix list
list[[
i,
j]]
or Part[
list,
i,
j]
give the ^(th) 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
Formatting constructs for vectors and matrices.
This builds a 3×3 matrix with elements .
This displays in standard two-dimensional matrix format.
This gives a vector with symbolic elements. You can use this in deriving general formulas that are valid with any choice of vector components.
Here are the dimensions of the matrix on the previous line.
This generates a 3×3 diagonal matrix.
c m multiply a matrix by a scalar
a.b dot product of two matrices
Some mathematical operations on matrices.
Here is the 2×2 matrix of symbolic variables that was defined.
This gives its determinant.
Here is the transpose of .
This gives the inverse of in symbolic form.
Here is a 3×3 rational matrix.
This gives its inverse.
Taking the dot product of the inverse with the original matrix gives the identity matrix.
Here is a 3×3 matrix.
This gives a numerical approximation to the matrix.
Here are numerical approximations to the eigenvalues.