LeviCivita , Permutations , InProduct , CrossProduct , ZeroVector , BaseVector , Identity , ZeroMatrix , DiagonalMatrix , IsMatrix , Normalize , Transpose , Determinant , Trace , Inverse , Minor , CoFactor , SolveMatrix , CharacteristicEquation , EigenValues , EigenVectors , IsHermitean , IsUnitary .

Linear Algebra

This chapter describes the commands for doing linear algebra. They can be used to manipulate vectors, represented as lists, and matrices, represented as lists of lists.

LeviCivita The totally anti-symmetric Levi Civita tensor
Permutations Form all permutations of a list
InProduct Inner product of vectors
CrossProduct Outer product of vectors
ZeroVector Create a vector with all zeroes
BaseVector Base vector
Identity Identity matrix
ZeroMatrix Matrix filled with zeroes
DiagonalMatrix Construct a diagonal matrix
IsMatrix Test whether argument is a matrix
Normalize Normalize a vector
Transpose Transpose of a matrix
Determinant Determinant of a matrix
Trace Trace of a matrix
Inverse Inverse of a matrix
Minor Principal minor of a matrix
CoFactor Cofactor of a matrix
SolveMatrix Solve a linear system
CharacteristicEquation Characteristic polynomial of a matrix
EigenValues Eigenvalues of a matrix
EigenVectors Eigenvectors of a matrix
IsHermitean Test whether a matrix is Hermitean
IsUnitary Test whether a matrix is unitary


LeviCivita -- The totally anti-symmetric Levi Civita tensor

Standard math library
Calling Sequence:
LeviCivita(list)
Parameters:
list - a list of integers 1 .. n in some order
Description:
"LeviCivita" implements the Levi Civita symbol. This is generally useful for tensor calculus. {list} should be a list of integers, and this function returns 1 if the integers are in successive order, eg. {1,2,3,...} would return 1. Swapping two elements of this list would return -1. So, LeviCivita( {2,1,3} ) would evaluate to -1.
Examples:
In> LeviCivita({1,2,3})
Out> 1;
In> LeviCivita({2,1,3})
Out> -1;
In> LeviCivita({2,2,3})
Out> 0;
See Also:
Permutations .


Permutations -- Form all permutations of a list

Standard math library
Calling Sequence:
Permutations(list)
Parameters:
list - a list of elements
Description:
Permutations returns a list with all the permutations of the original list.
Examples:
In> Permutations({a,b,c})
Out> {{a,b,c},{a,c,b},{c,a,b},{b,a,c},{b,c,a},{c,b,a}};
See Also:
LeviCivita .


InProduct -- Inner product of vectors

Standard math library
Calling Sequence:
InProduct(a,b)
a . b (prec. 3)
Parameters:
a, b - vectors of equal length
Description:
The inner product of the two vectors "a" and "b" is returned. The vectors need to have the same size.
Examples:
In> {a,b,c} . {d,e,f};
Out> a*d+b*e+c*f;
See Also:
CrossProduct .


CrossProduct -- Outer product of vectors

Standard math library
Calling Sequence:
CrossProduct(a,b)
a X b (prec. 3)
Parameters:
a, b - three-dimensional vectors
Description:
The outer product (also called the cross product) of the vectors "a" and "b" is returned. The result is perpendicular to both "a" and "b" and its length is the product of the lengths of the vectors. Both "a" and "b" have to be three-dimensional.
Examples:
In> {a,b,c} X {d,e,f};
Out> {b*f-c*e,c*d-a*f,a*e-b*d};
See Also:
InProduct .


ZeroVector -- Create a vector with all zeroes

Standard math library
Calling Sequence:
ZeroVector(n)
Parameters:
n - length of the vector to return
Description:
This command returns a vector of length "n", filled with zeroes.
Examples:
In> ZeroVector(4)
Out> {0,0,0,0};
See Also:
BaseVector , ZeroMatrix , IsZeroVector .


BaseVector -- Base vector

Standard math library
Calling Sequence:
BaseVector(k, n)
Parameters:
k - index of the base vector to construct
n - dimension of the vector
Description:
This command returns the "k"-th base vector of dimension "n". This is a vector of length "n" with all zeroes except for the "k"-th entry, which contains a 1.
Examples:
In> BaseVector(2,4)
Out> {0,1,0,0};
See Also:
ZeroVector , Identity .


Identity -- Identity matrix

Standard math library
Calling Sequence:
Identity(n)
Parameters:
n - size of the matrix
Description:
This commands returns the identity matrix of size "n" by "n". This matrix has ones on the diagonal while the other entries are zero.
Examples:
In> Identity(3)
Out> {{1,0,0},{0,1,0},{0,0,1}};
See Also:
BaseVector , ZeroMatrix , DiagonalMatrix .


ZeroMatrix -- Matrix filled with zeroes

Standard math library
Calling Sequence:
ZeroMatrix(n, m)
Parameters:
n - number of rows
m - number of columns
Description:
This command returns a matrix with "n" rows and "m" columns, completely filled with zeroes.
Examples:
In> ZeroMatrix(3,4)
Out> {{0,0,0,0},{0,0,0,0},{0,0,0,0}};
See Also:
ZeroVector , Identity .


DiagonalMatrix -- Construct a diagonal matrix

Standard math library
Calling Sequence:
DiagonalMatrix(d)
Parameters:
d - list of values to put on the diagonal
Description:
This command constructs a diagonal matrix, that is a square matrix whose off-diagonal entries are all zero. The elements of the vector "d" are put on the diagonal.
Examples:
In> DiagonalMatrix(1 .. 4)
Out> {{1,0,0,0},{0,2,0,0},{0,0,3,0},{0,0,0,4}};
See Also:
Identity , ZeroMatrix .


IsMatrix -- Test whether argument is a matrix

Standard math library
Calling Sequence:
IsMatrix(M)
Parameters:
M - a mathematical object
Description:
IsMatrix returns True if M is a matrix, False otherwise. Something is considered to be a matrix if it is a list and all the entries of this list are lists themselves.
Examples:
In> IsMatrix(ZeroMatrix(3,4))
Out> True;
In> IsMatrix(ZeroVector(4))
Out> False;
In> IsMatrix(3)
Out> False;
See Also:
IsVector .


Normalize -- Normalize a vector

Standard math library
Calling Sequence:
Normalize(v)
Parameters:
v - a vector
Description:
Return the normalized vector of v: a vector going in the same direction but with length 1.
Examples:
In> Normalize({3,4})
Out> {3/5,4/5};
In> % . %
Out> 1;
See Also:
InProduct , CrossProduct .


Transpose -- Transpose of a matrix

Standard math library
Calling Sequence:
Transpose(M)
Parameters:
M - a matrix
Description:
Transpose returns the transpose of a matrix M. Because matrices are just lists of lists, this is a useful operation too for lists.
Examples:
In> Transpose({{a,b}})
Out> {{a},{b}};


Determinant -- Determinant of a matrix

Standard math library
Calling Sequence:
Determinant(M)
Parameters:
M - a matrix
Description:
Returns the determinant of a matrix M.
Examples:
In> DiagonalMatrix(1 .. 4)
Out> {{1,0,0,0},{0,2,0,0},{0,0,3,0},{0,0,0,4}};
In> Determinant(%)
Out> 24;


Trace -- Trace of a matrix

Standard math library
Calling Sequence:
Trace(M)
Parameters:
M - a matrix
Description:
Trace returns the trace of a matrix M (defined as the sum of the elements on the diagonal of the matrix).
Examples:
In> DiagonalMatrix(1 .. 4)
Out> {{1,0,0,0},{0,2,0,0},{0,0,3,0},{0,0,0,4}};
In> Trace(%)
Out> 10;


Inverse -- Inverse of a matrix

Standard math library
Calling Sequence:
Inverse(M)
Parameters:
M - a matrix
Description:
Inverse returns the inverse of matrix M. The determinant of M should be non-zero. Because this function uses Determinant for calculating the inverse of a matrix, you can supply matrices with non-numeric matrix elements.
Examples:
In> DiagonalMatrix({a,b,c})
Out> {{a,0,0},{0,b,0},{0,0,c}};
In> Inverse(%)
Out> {{(b*c)/(a*b*c),0,0},{0,(a*c)/(a*b*c),0},{0,0,(a*b)/(a*b*c)}};
In> Simplify(%)
Out> {{1/a,0,0},{0,1/b,0},{0,0,1/c}};


Minor -- Principal minor of a matrix

Standard math library
Calling Sequence:
Minor(M,i,j)
Parameters:
M - a matrix
i, j - positive integers
Description:
Minor returns the minor of a matrix around the element (i,j). The minor is the determinant of the matrix excluding the "i"-th row and "j"-th column.
Examples:
In> A := {{1,2,3}, {4,5,6}, {7,8,9}};
Out> {{1,2,3},{4,5,6},{7,8,9}};
In> PrettyForm(A);

/                    \
| ( 1 ) ( 2 ) ( 3 )  |
|                    |
| ( 4 ) ( 5 ) ( 6 )  |
|                    |
| ( 7 ) ( 8 ) ( 9 )  |
\                    /

Out> True;
In> Minor(A,1,2);
Out> -6;
In> Determinant({{2,3}, {8,9}});
Out> -6;
See Also:
CoFactor , Determinant , Inverse .


CoFactor -- Cofactor of a matrix

Standard math library
Calling Sequence:
CoFactor(M,i,j)
Parameters:
M - a matrix
i, j - positive integers
Description:
CoFactor returns the cofactor of a matrix around the element (i,j). The cofactor is the minor times (-1)^(i+j)
Examples:
In> A := {{1,2,3}, {4,5,6}, {7,8,9}};
Out> {{1,2,3},{4,5,6},{7,8,9}};
In> PrettyForm(A);

/                    \
| ( 1 ) ( 2 ) ( 3 )  |
|                    |
| ( 4 ) ( 5 ) ( 6 )  |
|                    |
| ( 7 ) ( 8 ) ( 9 )  |
\                    /

Out> True;
In> CoFactor(A,1,2);
Out> 6;
In> Minor(A,1,2);
Out> -6;
In> Minor(A,1,2) * (-1)^(1+2);
Out> 6;
See Also:
Minor , Determinant , Inverse .


SolveMatrix -- Solve a linear system

Standard math library
Calling Sequence:
SolveMatrix(M,v)
Parameters:
M - a matrix
v - a vector
Description:
SolveMatrix returns the vector x that satisfies the equation "M x = v". The determinant of M should be non-zero.
Examples:
In> A := {{1,2}, {3,4}};
Out> {{1,2},{3,4}};
In> v := {5,6};
Out> {5,6};
In> x := SolveMatrix(A, v);
Out> {-4,9/2};
In> A * x;
Out> {5,6};
See Also:
Inverse , Solve , PSolve .


CharacteristicEquation -- Characteristic polynomial of a matrix

Standard math library
Calling Sequence:
CharacteristicEquation(matrix,var)
Parameters:
matrix - a matrix
var - a free variable
Description:
CharacteristicEquation returns the characteristic equation of "matrix", using "var". The zeros of this equation are the eigenvalues of the matrix, Det(matrix-I*var);
Examples:
In> DiagonalMatrix({a,b,c})
Out> {{a,0,0},{0,b,0},{0,0,c}};
In> CharacteristicEquation(%,x)
Out> (a-x)*(b-x)*(c-x);
In> Expand(%,x)
Out> (b+a+c)*x^2-x^3-((b+a)*c+a*b)*x+a*b*c;
See Also:
EigenValues , EigenVectors .


EigenValues -- Eigenvalues of a matrix

Standard math library
Calling Sequence:
EigenValues(matrix)
Parameters:
matrix - a square matrix
Description:
EigenValues returns the eigenvalues of a matrix. The eigenvalues x of a matrix M are the numbers such that M*v=x*v for some vector.
It first determines the characteristic equation, and then factorizes this equation, returning the roots of the characteristic equation det(matrix-x*identity).
Examples:
In> M:={{1,2},{2,1}}
Out> {{1,2},{2,1}};
In> EigenValues(M)
Out> {3,-1};
See Also:
EigenVectors , CharacteristicEquation .


EigenVectors -- Eigenvectors of a matrix

Standard math library
Calling Sequence:
EigenVectors(matrix,eigenvalues) Standard math library
Parameters:
matrix - a square matrix
eigenvalues - list of eigenvalues as returned by EigenValues
Description:
EigenVectors returns a list of the eigenvectors of a matrix. It uses the eigenvalues and the matrix to set up n equations with n unknowns for each eigenvalue, and then calls Solve to determine the values of each vector.
Examples:
In> M:={{1,2},{2,1}}
Out> {{1,2},{2,1}};
In> e:=EigenValues(M)
Out> {3,-1};
In> EigenVectors(M,e)
Out> {{-ki2/ -1,ki2},{-ki2,ki2}};
See Also:
EigenValues , CharacteristicEquation .


IsHermitean -- Test whether a matrix is Hermitean

Standard math library
Calling Sequence:
IsHermitean(A)
Parameters:
A - square matrix
Description:
IsHermitean(A) returns True if A is Hermitean and False otherwise. A is a Hermitean matrix iff Conjugate(Transpose(A))=A. For real matrices A is tested to be symmetric.
Examples:
In> IsHermitean({{0,I},{-I,0}})
Out> True;
In> IsHermitean({{0,I},{2,0}})
Out> False;
See Also:
IsUnitary .


IsUnitary -- Test whether a matrix is unitary

Standard math library
Calling Sequence:
IsUnitary(A)
Parameters:
A - square matrix
Description:
This function tries to find out if A is unitary. Matrix A is orthogonal iff A^(-1) = Transpose(Conjugate(A)). This is equivalent to the fact that the columns of A build an orthonormal system (in respect to the scalar product defined by InProduct).
Examples:
In> IsUnitary({{0,I},{-I,0}})
Out> True;
In> IsUnitary({{0,I},{2,0}})
Out> False;
See Also:
IsHermitean .