This section is applicable for Matrices and Vectors.
You define vectors as a list e.g. Y = { 1, 2, 3 } defines the vector Y, whose x,y and z components are 1,2 and 3. Note you must use curly brackets { }
The scalar (dot) product and vector (cross) product are performed with the Dot and Cross in-built functions:
Dot[ u, v ] gives the scalar (or dot) product of u and v. Note that u and v must have the same dimensionality.
Cross[ u, v ] gives the vector (or cross) product of u and v. Note that u and v must be 3-dimensional.
Norm[ u ] gives the length of the vector u
Note that there are three important things to note about matrices in Mathematica.
1. Matrices are written as lists of lists so all the elements appear on one line, e.g. mat = {{ 10,3 } , { -7,5 }} defines the matrix called mat which has 10 and 3 on the first row, and -7 and 5 on the second row.
2. Multiplying a matrix by another is performed with matrix1 . matrix2 and not matrix1 * matrix2 or matrix1 matrix2 Also multiplying a matrix by a vector is similarly performed with matrix . vector If you want to multiply a matrix or vector by a scalar number, then you can use number matrix or number*matrix (e.g. 4 matrix or 4*matrix).
3. It can be difficult to read matrices in Mathematica because they are written as lists (i.e. all the elements normally appear on one line, e.g. mat = {{ 10,3 } , { -7,5 }}. One way of making this easier it to convert a particular cell to the Traditional Form. To do this you just select the Cell menu item, and then select Convert To and then, finally, TraditionalForm. You can make this format the default by choosing it in the Default Output FormatType in the Cell menu.
You can access a number of in-built functions associated with matrices:
Name | Example Usage |
IdentityMatrix[ n ] | 4 IdentityMatrix[3] |
DiagonalMatrix[{ n1,n2,... }] | m=DiagonalMatrix[{ 3,8,-9 }] |
Inverse[ matrix ] | Inverse[ m ] |
Det[ matrix ] | Det[ m ] |
Transpose[ matrix ] | Transpose[ m ] |
Eigenvalues[ matrix ] | Eigenvalues[ m ] |
Eigenvectors[ matrix] | Eigenvalues[ m ] |
There are two ways of extracting elements of vectors.
There is corresponding usage in the matrix case.
Note that Part[ matrix,m ] and matrix[[ mat ]] returns the m-th row of the matrix mat.