LeviCivita | totally anti-symmetric Levi-Civita symbol |
Permutations | get all permutations of a list |
Dot, . | get dot product of tensors |
InProduct | inner product of vectors (deprecated) |
CrossProduct | outer product of vectors |
Outer, o | get outer tensor product |
ZeroVector | create a vector with all zeroes |
BaseVector | base vector |
Identity | make identity matrix |
ZeroMatrix | make a zero matrix |
Diagonal | extract the diagonal from a matrix |
DiagonalMatrix | construct a diagonal matrix |
OrthogonalBasis | create an orthogonal basis |
OrthonormalBasis | create an orthonormal basis |
IsScalar | test for a scalar |
IsVector | test for a vector |
IsMatrix | test for a matrix |
IsSquareMatrix | test for a square matrix |
Normalize | normalize a vector |
Transpose | get transpose of a matrix |
Determinant | determinant of a matrix |
Trace | trace of a matrix |
Inverse | get inverse of a matrix |
Minor | get principal minor of a matrix |
CoFactor | cofactor of a matrix |
MatrixPower | get nth power of a square matrix |
SolveMatrix | solve a linear system |
CharacteristicEquation | get characteristic polynomial of a matrix |
EigenValues | get eigenvalues of a matrix |
EigenVectors | get eigenvectors of a matrix |
IsHermitian | test for a Hermitian matrix |
IsOrthogonal | test for an orthogonal matrix |
IsDiagonal | test for a diagonal matrix |
IsLowerTriangular, IsUpperTriangular | test for a lower or an upper triangular matrix |
IsSymmetric | test for a symmetric matrix |
IsSkewSymmetric | test for a skew-symmetric matrix |
IsUnitary | test for a unitary matrix |
IsIdempotent | test for an idempotent matrix |
JacobianMatrix | calculate the Jacobian matrix of n functions in n variables |
VandermondeMatrix | create the Vandermonde matrix |
HessianMatrix | create the Hessian matrix |
Sparsity | get the sparsity of a matrix |
HilbertMatrix | create a Hilbert matrix |
HilbertInverseMatrix | create a Hilbert inverse matrix |
ToeplitzMatrix | create a Toeplitz matrix |
WronskianMatrix | create the Wronskian matrix |
SylvesterMatrix | calculate the Sylvester matrix of two polynomials |
MatrixSolve | solve a system of equations |
Cholesky | find the Cholesky Decomposition |
RandomIntegerMatrix | generate a matrix of random integers |
LeviCivita(list) |
In> LeviCivita({1,2,3}) Out> 1; In> LeviCivita({2,1,3}) Out> -1; In> LeviCivita({2,2,3}) Out> 0; |
Permutations(list) |
In> Permutations({a,b,c}) Out> {{a,b,c},{a,c,b},{c,a,b},{b,a,c}, {b,c,a},{c,b,a}}; |
Dot(t1,t2) t1 . t2 |
In> Dot({1,2},{3,4}) Out> 11; In> Dot({{1,2},{3,4}},{5,6}) Out> {17,39}; In> Dot({5,6},{{1,2},{3,4}}) Out> {23,34}; In> Dot({{1,2},{3,4}},{{5,6},{7,8}}) Out> {{19,22},{43,50}}; |
Or, using the "."-Operator: |
In> {1,2} . {3,4} Out> 11; In> {{1,2},{3,4}} . {5,6} Out> {17,39}; In> {5,6} . {{1,2},{3,4}} Out> {23,34}; In> {{1,2},{3,4}} . {{5,6},{7,8}} Out> {{19,22},{43,50}}; |
InProduct(a,b) |
This function is superceded by the . operator.
In> {a,b,c} . {d,e,f}; Out> a*d+b*e+c*f; |
CrossProduct(a,b) a X b |
In> {a,b,c} X {d,e,f}; Out> {b*f-c*e,c*d-a*f,a*e-b*d}; |
Outer(t1,t2) t1 o t2 |
In> Outer({1,2},{3,4,5}) Out> {{3,4,5},{6,8,10}}; In> Outer({a,b},{c,d}) Out> {{a*c,a*d},{b*c,b*d}}; |
Or, using the "o"-Operator: |
In> {1,2} o {3,4,5} Out> {{3,4,5},{6,8,10}}; In> {a,b} o {c,d} Out> {{a*c,a*d},{b*c,b*d}}; |
ZeroVector(n) |
In> ZeroVector(4) Out> {0,0,0,0}; |
BaseVector(k, n) |
n -- dimension of the vector
In> BaseVector(2,4) Out> {0,1,0,0}; |
Identity(n) |
In> Identity(3) Out> {{1,0,0},{0,1,0},{0,0,1}}; |
ZeroMatrix(n) ZeroMatrix(n, m) |
m -- number of columns
In> ZeroMatrix(3,4) Out> {{0,0,0,0},{0,0,0,0},{0,0,0,0}}; In> ZeroMatrix(3) Out> {{0,0,0},{0,0,0},{0,0,0}}; |
Diagonal(A) |
In> Diagonal(5*Identity(4)) Out> {5,5,5,5}; In> Diagonal(HilbertMatrix(3)) Out> {1,1/3,1/5}; |
DiagonalMatrix(d) |
In> DiagonalMatrix(1 .. 4) Out> {{1,0,0,0},{0,2,0,0},{0,0,3,0},{0,0,0,4}}; |
OrthogonalBasis(W) |
In> OrthogonalBasis({{1,1,0},{2,0,1},{2,2,1}}) Out> {{1,1,0},{1,-1,1},{-1/3,1/3,2/3}}; |
OrthonormalBasis(W) |
In> OrthonormalBasis({{1,1,0},{2,0,1},{2,2,1}}) Out> {{Sqrt(1/2),Sqrt(1/2),0},{Sqrt(1/3),-Sqrt(1/3),Sqrt(1/3)}, {-Sqrt(1/6),Sqrt(1/6),Sqrt(2/3)}}; |
IsScalar(expr) |
In> IsScalar(7) Out> True; In> IsScalar(Sin(x)+x) Out> True; In> IsScalar({x,y}) Out> False; |
IsVector(expr) |
IsVector(pred,expr) |
pred -- predicate test (e.g. IsNumber, IsInteger, ...)
In> IsVector({a,b,c}) Out> True; In> IsVector({a,{b},c}) Out> False; In> IsVector(IsInteger,{1,2,3}) Out> True; In> IsVector(IsInteger,{1,2.5,3}) Out> False; |
IsMatrix(expr) |
IsMatrix(pred,expr) |
pred -- predicate test (e.g. IsNumber, IsInteger, ...)
In> IsMatrix(1) Out> False; In> IsMatrix({1,2}) Out> False; In> IsMatrix({{1,2},{3,4}}) Out> True; In> IsMatrix(IsRational,{{1,2},{3,4}}) Out> False; In> IsMatrix(IsRational,{{1/2,2/3},{3/4,4/5}}) Out> True; |
IsSquareMatrix(expr) |
IsSquareMatrix(pred,expr) |
pred -- predicate test (e.g. IsNumber, IsInteger, ...)
In> IsSquareMatrix({{1,2},{3,4}}); Out> True; In> IsSquareMatrix({{1,2,3},{4,5,6}}); Out> False; In> IsSquareMatrix(IsBoolean,{{1,2},{3,4}}); Out> False; In> IsSquareMatrix(IsBoolean,{{True,False},{False,True}}); Out> True; |
Normalize(v) |
In> v:=Normalize({3,4}) Out> {3/5,4/5}; In> v . v Out> 1; |
Transpose(M) |
In> Transpose({{a,b}}) Out> {{a},{b}}; |
Determinant(M) |
In> A:=DiagonalMatrix(1 .. 4) Out> {{1,0,0,0},{0,2,0,0},{0,0,3,0},{0,0,0,4}}; In> Determinant(A) Out> 24; |
Trace(M) |
In> A:=DiagonalMatrix(1 .. 4) Out> {{1,0,0,0},{0,2,0,0},{0,0,3,0},{0,0,0,4}}; In> Trace(A) Out> 10; |
Inverse(M) |
In> A:=DiagonalMatrix({a,b,c}) Out> {{a,0,0},{0,b,0},{0,0,c}}; In> B:=Inverse(A) Out> {{(b*c)/(a*b*c),0,0},{0,(a*c)/(a*b*c),0}, {0,0,(a*b)/(a*b*c)}}; In> Simplify(B) Out> {{1/a,0,0},{0,1/b,0},{0,0,1/c}}; |
Minor(M,i,j) |
i, j - positive integers
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; |
CoFactor(M,i,j) |
i, j - positive integers
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; |
MatrixPower(mat,n) |
n -- an integer
In> A:={{1,2},{3,4}} Out> {{1,2},{3,4}}; In> MatrixPower(A,0) Out> {{1,0},{0,1}}; In> MatrixPower(A,1) Out> {{1,2},{3,4}}; In> MatrixPower(A,3) Out> {{37,54},{81,118}}; In> MatrixPower(A,-3) Out> {{-59/4,27/4},{81/8,-37/8}}; |
SolveMatrix(M,v) |
v -- a vector
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}; |
CharacteristicEquation(matrix,var) |
var -- a free variable
In> A:=DiagonalMatrix({a,b,c}) Out> {{a,0,0},{0,b,0},{0,0,c}}; In> B:=CharacteristicEquation(A,x) Out> (a-x)*(b-x)*(c-x); In> Expand(B,x) Out> (b+a+c)*x^2-x^3-((b+a)*c+a*b)*x+a*b*c; |
EigenValues(matrix) |
It first determines the characteristic equation, and then factorizes this equation, returning the roots of the characteristic equation Det(matrix-x*identity).
In> M:={{1,2},{2,1}} Out> {{1,2},{2,1}}; In> EigenValues(M) Out> {3,-1}; |
EigenVectors(A,eigenvalues) |
eigenvalues -- list of eigenvalues as returned by EigenValues
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}}; |
IsHermitian(A) |
In> IsHermitian({{0,I},{-I,0}}) Out> True; In> IsHermitian({{0,I},{2,0}}) Out> False; |
IsOrthogonal(A) |
In> A := {{1,2,2},{2,1,-2},{-2,2,-1}}; Out> {{1,2,2},{2,1,-2},{-2,2,-1}}; In> PrettyForm(A/3) |
/ \ | / 1 \ / 2 \ / 2 \ | | | - | | - | | - | | | \ 3 / \ 3 / \ 3 / | | | | / 2 \ / 1 \ / -2 \ | | | - | | - | | -- | | | \ 3 / \ 3 / \ 3 / | | | | / -2 \ / 2 \ / -1 \ | | | -- | | - | | -- | | | \ 3 / \ 3 / \ 3 / | \ / Out> True; In> IsOrthogonal(A/3) Out> True; |
IsDiagonal(A) |
In> IsDiagonal(Identity(5)) Out> True; In> IsDiagonal(HilbertMatrix(5)) Out> False; |
IsLowerTriangular(A) IsUpperTriangular(A) |
IsLowerTriangular(A) returns True if A is a lower triangular matrix and False otherwise. IsUpperTriangular(A) returns True if A is an upper triangular matrix and False otherwise.
In> IsUpperTriangular(Identity(5)) Out> True; In> IsLowerTriangular(Identity(5)) Out> True; In> IsLowerTriangular({{1,2},{0,1}}) Out> False; In> IsUpperTriangular({{1,2},{0,1}}) Out> True; |
In> IsUpperTriangular({{1,2,3},{0,1,2}}) Out> False; |
IsSymmetric(A) |
In> A := {{1,0,0,0,1},{0,2,0,0,0},{0,0,3,0,0}, {0,0,0,4,0},{1,0,0,0,5}}; In> PrettyForm(A) |
/ \ | ( 1 ) ( 0 ) ( 0 ) ( 0 ) ( 1 ) | | | | ( 0 ) ( 2 ) ( 0 ) ( 0 ) ( 0 ) | | | | ( 0 ) ( 0 ) ( 3 ) ( 0 ) ( 0 ) | | | | ( 0 ) ( 0 ) ( 0 ) ( 4 ) ( 0 ) | | | | ( 1 ) ( 0 ) ( 0 ) ( 0 ) ( 5 ) | \ / Out> True; In> IsSymmetric(A) Out> True; |
IsSkewSymmetric(A) |
In> A := {{0,-1},{1,0}} Out> {{0,-1},{1,0}}; In> PrettyForm(%) |
/ \ | ( 0 ) ( -1 ) | | | | ( 1 ) ( 0 ) | \ / Out> True; In> IsSkewSymmetric(A); Out> True; |
IsUnitary(A) |
A 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 (with respect to the scalar product defined by InProduct).
In> IsUnitary({{0,I},{-I,0}}) Out> True; In> IsUnitary({{0,I},{2,0}}) Out> False; |
IsIdempotent(A) |
In> IsIdempotent(ZeroMatrix(10,10)); Out> True; In> IsIdempotent(Identity(20)) Out> True; |
JacobianMatrix(functions,variables) |
variables -- an n-dimensional vector of variables
The ( i, j)-th element of the Jacobian matrix is defined as the derivative of i-th function with respect to the j-th variable.
In> JacobianMatrix( {Sin(x),Cos(y)}, {x,y} ); Out> {{Cos(x),0},{0,-Sin(y)}}; In> PrettyForm(%) |
/ \ | ( Cos( x ) ) ( 0 ) | | | | ( 0 ) ( -( Sin( y ) ) ) | \ / |
VandermondeMatrix(vector) |
The ( i, j)-th element of the Vandermonde matrix is defined as i^(j-1).
In> VandermondeMatrix({1,2,3,4}) Out> {{1,1,1,1},{1,2,3,4},{1,4,9,16},{1,8,27,64}}; In>PrettyForm(%) |
/ \ | ( 1 ) ( 1 ) ( 1 ) ( 1 ) | | | | ( 1 ) ( 2 ) ( 3 ) ( 4 ) | | | | ( 1 ) ( 4 ) ( 9 ) ( 16 ) | | | | ( 1 ) ( 8 ) ( 27 ) ( 64 ) | \ / |
HessianMatrix(function,var) |
var -- an n-dimensional vector of variables
If f(x) is a function of an n-dimensional vector x, then the ( i, j)-th element of the Hessian matrix of the function f(x) is defined as Deriv(x[i])Deriv(x[j])f(x). If the third order mixed partials are continuous, then the Hessian matrix is symmetric (a standard theorem of calculus).
The Hessian matrix is used in the second derivative test to discern if a critical point is a local maximum, a local minimum or a saddle point.
In> HessianMatrix(3*x^2-2*x*y+y^2-8*y, {x,y} ) Out> {{6,-2},{-2,2}}; In> PrettyForm(%) |
/ \ | ( 6 ) ( -2 ) | | | | ( -2 ) ( 2 ) | \ / |
Sparsity(matrix) |
In> Sparsity(Identity(2)) Out> 0.5; In> Sparsity(Identity(10)) Out> 0.9; In> Sparsity(HankelMatrix(10)) Out> 0.45; In> Sparsity(HankelMatrix(100)) Out> 0.495; In> Sparsity(HilbertMatrix(10)) Out> 0; In> Sparsity(ZeroMatrix(10,10)) Out> 1; |
HilbertMatrix(n) HilbertMatrix(n,m) |
In> PrettyForm(HilbertMatrix(4)) |
/ \ | ( 1 ) / 1 \ / 1 \ / 1 \ | | | - | | - | | - | | | \ 2 / \ 3 / \ 4 / | | | | / 1 \ / 1 \ / 1 \ / 1 \ | | | - | | - | | - | | - | | | \ 2 / \ 3 / \ 4 / \ 5 / | | | | / 1 \ / 1 \ / 1 \ / 1 \ | | | - | | - | | - | | - | | | \ 3 / \ 4 / \ 5 / \ 6 / | | | | / 1 \ / 1 \ / 1 \ / 1 \ | | | - | | - | | - | | - | | | \ 4 / \ 5 / \ 6 / \ 7 / | \ / |
HilbertInverseMatrix(n) |
In> PrettyForm(HilbertInverseMatrix(4)) |
/ \ | ( 16 ) ( -120 ) ( 240 ) ( -140 ) | | | | ( -120 ) ( 1200 ) ( -2700 ) ( 1680 ) | | | | ( 240 ) ( -2700 ) ( 6480 ) ( -4200 ) | | | | ( -140 ) ( 1680 ) ( -4200 ) ( 2800 ) | \ / |
ToeplitzMatrix(N) |
In> PrettyForm(ToeplitzMatrix({1,2,3,4,5})) |
/ \ | ( 1 ) ( 2 ) ( 3 ) ( 4 ) ( 5 ) | | | | ( 2 ) ( 1 ) ( 2 ) ( 3 ) ( 4 ) | | | | ( 3 ) ( 2 ) ( 1 ) ( 2 ) ( 3 ) | | | | ( 4 ) ( 3 ) ( 2 ) ( 1 ) ( 2 ) | | | | ( 5 ) ( 4 ) ( 3 ) ( 2 ) ( 1 ) | \ / |
WronskianMatrix(func,var) |
var -- a variable to differentiate with respect to
The Wronskian matrix is created by putting each function as the first element of each column, and filling in the rest of each column by the ( i-1)-th derivative, where i is the current row.
The Wronskian matrix is used to verify that the n functions are linearly independent, usually solutions to a differential equation. If the determinant of the Wronskian matrix is zero, then the functions are dependent, otherwise they are independent.
In> WronskianMatrix({Sin(x),Cos(x),x^4},x); Out> {{Sin(x),Cos(x),x^4},{Cos(x),-Sin(x),4*x^3}, {-Sin(x),-Cos(x),12*x^2}}; In> PrettyForm(%) |
/ \ | ( Sin( x ) ) ( Cos( x ) ) / 4 \ | | \ x / | | | | ( Cos( x ) ) ( -( Sin( x ) ) ) / 3 \ | | \ 4 * x / | | | | ( -( Sin( x ) ) ) ( -( Cos( x ) ) ) / 2 \ | | \ 12 * x / | \ / |
In> A:=Determinant( WronskianMatrix( {x^4,x^3,2*x^4 + 3*x^3},x ) ) Out> x^4*3*x^2*(24*x^2+18*x)-x^4*(8*x^3+9*x^2)*6*x +(2*x^4+3*x^3)*4*x^3*6*x-4*x^6*(24*x^2+18*x)+x^3 *(8*x^3+9*x^2)*12*x^2-(2*x^4+3*x^3)*3*x^2*12*x^2; In> Simplify(A) Out> 0; |
SylvesterMatrix(poly1,poly2,variable) |
poly2 -- polynomial
variable -- variable to express the matrix for
The Sylvester matrix is closely related to the resultant, which is defined as the determinant of the Sylvester matrix. Two polynomials share common roots only if the resultant is zero.
In> ex1:= x^2+2*x-a Out> x^2+2*x-a; In> ex2:= x^2+a*x-4 Out> x^2+a*x-4; In> A:=SylvesterMatrix(ex1,ex2,x) Out> {{1,2,-a,0},{0,1,2,-a}, {1,a,-4,0},{0,1,a,-4}}; In> B:=Determinant(A) Out> 16-a^2*a- -8*a-4*a+a^2- -2*a^2-16-4*a; In> Simplify(B) Out> 3*a^2-a^3; |
The above example shows that the two polynomials have common zeros if a=3.
MatrixSolve(A,b) |
b -- row vector
In> A:={{2,4,-2,-2},{1,2,4,-3},{-3,-3,8,-2},{-1,1,6,-3}}; Out> {{2,4,-2,-2},{1,2,4,-3},{-3,-3,8,-2},{-1,1,6,-3}}; In> b:={-4,5,7,7}; Out> {-4,5,7,7}; In> MatrixSolve(A,b); Out> {1,2,3,4}; |
Cholesky(A) |
In> A:={{4,-2,4,2},{-2,10,-2,-7},{4,-2,8,4},{2,-7,4,7}} Out> {{4,-2,4,2},{-2,10,-2,-7},{4,-2,8,4},{2,-7,4,7}}; In> R:=Cholesky(A); Out> {{2,-1,2,1},{0,3,0,-2},{0,0,2,1},{0,0,0,1}}; In> Transpose(R)*R = A Out> True; In> Cholesky(4*Identity(5)) Out> {{2,0,0,0,0},{0,2,0,0,0},{0,0,2,0,0},{0,0,0,2,0},{0,0,0,0,2}}; In> Cholesky(HilbertMatrix(3)) Out> {{1,1/2,1/3},{0,Sqrt(1/12),Sqrt(1/12)},{0,0,Sqrt(1/180)}}; In> Cholesky(ToeplitzMatrix({1,2,3})) In function "Check" : CommandLine(1) : "Cholesky: Matrix is not positive definite" |
RandomIntegerMatrix(rows,cols,from,to) |
cols -- number of cols in matrix
from -- lower bound
to -- upper bound
In> PrettyForm( RandomIntegerMatrix(5,5,-2^10,2^10) ) |
/ \ | ( -506 ) ( 749 ) ( -574 ) ( -674 ) ( -106 ) | | | | ( 301 ) ( 151 ) ( -326 ) ( -56 ) ( -277 ) | | | | ( 777 ) ( -761 ) ( -161 ) ( -918 ) ( -417 ) | | | | ( -518 ) ( 127 ) ( 136 ) ( 797 ) ( -406 ) | | | | ( 679 ) ( 854 ) ( -78 ) ( 503 ) ( 772 ) | \ / |