Integer Matrices etc. --------------------- Eigenvalues [ { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } } ] Matrix Notation --------------- a = { { 11, 12, 13 }, { 21, 22, 23 }, { 31, 32, 33 }, { 41, 42, 43 } } b = { 7, 8, 9 } TableForm [ a ] a [[ 3, 2 ]] a . b Row Major or Column Major? -------------------------- a = { { 11, 12, 13 }, { 21, 22, 23 }, { 31, 32, 33 } } a [[ 3, 2 ]] Index Ranges ------------ a = Range [ 10 ] Span [ 5, 7 ] a [[ 5 ;; 7 ]] a [[ Span [ 5, 7 ] ]] a [[ 5 ;; ]] a [[ ;; 5 ]] a [[ ;; ]] a [[ 3 ;; 8 ;; 2 ]] a [[ Span [ 3, 8, 2 ] ]] Matrices as Lists ----------------- a = { 9.8, 8.7, 7.6, 6.5, 5.4, 4.3, 3.2, 2.1, 1.0 } b = { { 1.2, 2.3, 3.4, 4.5 }, { 5.6, 6.7, 7.8, 8.9 }, { 9.0, 0.1, 1.2, 2.3 } } // TableForm c = { { 1 + x ^ 2, x * y }, { - x * y, 1 + y ^ 2 } } TableForm [ c ] Matrix Constructors ------------------- a = ConstantArray [ p + q , { 5 } ] a = ConstantArray [ p + q , { 2, 2 } ] a = IdentityMatrix [ 3 ] a = DiagonalMatrix [ { P, Q, R } ] a = HilbertMatrix [ 3 ] Importing from Matlab --------------------- c = Import [ "matthew.mat" ] a = c [[ 1 ]] b = c [[ 2 ]] [[ 1 ]] Importing in CSV ---------------- Import [ "matthew.csv" ] Matrices from Expressions ------------------------- Table [ 1.23, { 3 } ] Table [ n ^ 2, { n, 5 } ] Table [ n ^ 2, { n, 3, 5 } ] Table [ n ^ 2, { n, 1, 5, 3 } ] Table [ n ^ 2, { n, 1, 5, -3 } ] Table [ n ^ 2, { n, 5, 1, -3 } ] Table [ n ^ 2 + 100 * 2 ^ m, { m, 3 }, { n, 5 } ] Table [ n ^ 2 + 100 * 2 ^ m, { m, 3 }, { n, m } ] Table [ p ^ m + q ^ n, { m, 3 }, { n, 3 } ] // TableForm Elementwise Arithmetic ---------------------- a = { { Pi, x + y ^ 2 }, { y / x, 0 } } TableForm [ Sin [ a + Pi / 2 ] ] a = { { Pi, x + y }, { x * y, 0 } } b = { Pi, x + y, x * y, 0 } Sine [ a + b ] Sine [ { { Pi, x + y }, { x y, 0 } } + { Pi, x + y, x y, 0 } ] a = { { x ^ 2 - y ^ 2, x ^ 3 + y ^ 3 }, { x ^ 3 + y ^ 3, x ^ 3 - y ^ 3 } } b = { { x - y, x + y }, { x + y, x - y } } Cancel [ a / b ] // TableForm True Matrix Operations ---------------------- Dot [ a, b, c ] a = { { 1, 2 }, { 3, 4 }, { 5, 6 } } b = { 9, 8 } a . b Vector Operations ----------------- a = Normalize [ { 1.0, 2.0, 3.0 } ] Norm [ a ] Simple Matrix Operations ------------------------ a = Transpose [ { { p, q }, { r, s } } ] Tr [ a ] (* Note that this is the trace *) Enquiry Function ---------------- Dimensions [ { 1, 4, 7 } ] Dimensions [ { { 1, 2 }, { 3, 4}, { 5, 6 } } ] a = Table [ n ^ 2 + 100 * 2 ^ m, { m, 3 }, { n, m } ] Dimensions [ a ] Matrix Powering --------------- MatrixPower [ { { 1, x }, { y, 1 } }, 3 ] MatrixExp [ { { 1.0, 2.0 }, { 3.0, 4.0 } } ] Inverse ------- Inverse [ { { 1.2, 3.4 }, { 5.6, 7.8 } } ] Inverse [ { { 1.2 - I, 3.4 }, { 5.6, 7.8 + 2.0 * I } } ] Inverse [ { { 1.2, 3.4 }, { 2.4, 6.8 } } ] PseudoInverse [ { { 1.2, 3.4 }, { 2.4, 6.8 } } ] Determinant ----------- Det [ { { 1.2, 3.4 }, { 5.6, 7.8 } } ] Det [ { { 1.2 - I, 3.4 }, { 5.6, 7.8 + 2.0 * I } } ] Det [ HilbertMatrix [ 2000 ] * 1.0 ] Enquiry Functions ----------------- PositiveDefiniteMatrixQ [ 1.0 * HilbertMatrix [ 10 ] ] PositiveDefiniteMatrixQ [ 1.0 * HilbertMatrix [ 20 ] ] Rank And Null Space ------------------- a = HilbertMatrix [ 100 ] * 1.0 ; { MatrixRank [ a ], MatrixRank [ a . a ] } Dimensions [ NullSpace [ a . a ] ] Linear Equations ---------------- a = { { 4.2, 2.2, - 3.9, 9.3, 0.1 }, { 8.6, 0.0, 0.7, - 2.3, - 0.3 }, { 8.4, - 5.9, - 8.1, 9.6, 3.8 }, {- 0.8, - 9.4, - 9.9, 9.9, 5.0 }, {- 1.3, - 8.1, 0.6, - 9.2, - 7.3 } } b = { - 6.8, 2.3, 2.7, - 7.0, 2.0 } LinearSolve [ a, b ] a = { { 4.2 + 2.2 I, - 3.9 + 9.3 I, 0.1 + 0.0 I }, { 8.6 + 0.0 I, 0.7 - 2.3 I, 0.0 - 0.3 I }, { 8.4 - 5.9 I, - 8.1 + 9.6 I, 3.8 - 0.8 I } } b = { - 6.8 + 2.3 I, 2.7 - 7.0 I, 2.0 + 0.0 I } LinearSolve [ a, b ] LinearSolve [ { { 1.2, 3.4 }, { 2.4, 6.8 } }, { 1.0, 1.0 } ] LinearSolve [ HilbertMatrix [ 10 ] * 1.0, \ RandomReal [ { -1.0, 1.0 }, { 10, 10 } ] a = { { 1.0, 1.0 }, { 1.0, 1.0 } } a . { 1.0, 0.0 } a . { 0.0, 1.0 } LinearSolve [ a, {1.0, 1.0} ] Fourier Transforms ------------------ a = { - 0.92, 9.1, 2.3, 5.7, 4.9, -2.8, - 5.6, 6.7, -7.0, 9.0 } b = Fourier [ a ] Fourier [ b ] Eigenvalues ----------- a = { { 4.2, 2.2, - 3.9, 9.3, 0.1 }, { 8.6, 0.0, 0.7, - 2.3, - 0.3 }, { 8.4, - 5.9, - 8.1, 9.6, 3.8 }, { - 0.8, - 9.4, - 9.9, 9.9, 5.0 }, { - 1.3, - 8.1, 0.6, - 9.2, - 7.3 } } Eigenvalues [ a ] Eigenvectors [ a ] (* omitted as it is a bit messy *) Eigenvalues [ HilbertMatrix [ 3 ] * 1.0 ] Eigenvectors [ HilbertMatrix [ 3 ] * 1.0 ] a = { { 4.2 + 2.2 I, - 3.9 + 9.3 I, 0.1 + 8.6 I }, { 0.0 + 0.7 I, - 2.3 - 0.3 I, 8.4 - 5.9 I }, { - 8.1 + 9.6 I, 3.8 - 0.8 I, - 9.4 - 9.9 I } } Eigenvalues [ a ] Eigenvectors [ a ] (* omitted as it is a bit messy *) a = { { 1.0, 1.0 }, { 0.0, 1.0 } } Eigenvalues [ a ] Eigenvectors [ a ] Characteristic Polynomial ------------------------- a = { { 4.2, 2.2, - 3.9, 9.3, 0.1 }, { 8.6, 0.0, 0.7, - 2.3, - 0.3 }, { 8.4, - 5.9, - 8.1, 9.6, 3.8 }, { - 0.8, - 9.4, - 9.9, 9.9, 5.0 }, { - 1.3, - 8.1, 0.6, - 9.2, - 7.3 } } CharacteristicPolynomial [ a, p ] Singular Values --------------- a = { { 4.2, 2.2, - 3.9, 9.3, 0.1 }, { 8.6, 0.0, 0.7, - 2.3, - 0.3 }, { 8.4, - 5.9, - 8.1, 9.6, 3.8 }, { - 0.8, - 9.4, - 9.9, 9.9, 5.0 }, { - 1.3, - 8.1, 0.6, - 9.2, - 7.3 } } Eigenvalues [ a ] SingularValueList [ a ] Eigenvectors [ a ] b = SingularValueDecomposition [ a ] b [[ 1 ]] . b [[ 2 ]] . Transpose [ b [[ 3 ]] ] a = HilbertMatrix [ 3 ] * 1.0 Eigenvalues [ a ] SingularValueList [ a ] Eigenvectors [ a ] b = SingularValueDecomposition [ a ] b [[ 1 ]] . b [[ 2 ]] . Transpose [ b [[ 3 ]] ] a = { { 1.0, 1.0 }, { 0.0, 1.0 } } SingularValueList [ a ] b = SingularValueDecomposition [ a ] b [[ 1 ]] . b [[ 2 ]] . Transpose [ b [[ 3 ]] ] Solution of Equations --------------------- a = HilbertMatrix [ 10 ] b = ConstantArray [ 1, 10 ] c = LinearSolve [ a, b ] d = LinearSolve [ a + 0.0, b ] d = N [ LinearSolve [ N [ a, 30], b ], 6 ]