## 6.5.2 Matrix algebra

Matrices can be multiplied by one another and by vectors to perform matrix arithmetic. This not only allows matrix equations to be solved, but also allows transformation matrices to be applied to vector positions on the vector graphics canvas. All of Pyxplot’s vector graphics commands, which will be described in detail in Chapter 10, can accept positions as either comma-separated numerical components, or as vector objects. The following example demonstrates the use of a rotation matrix:

```rotate(a) = matrix( [[cos(a),-sin(a)], \
[sin(a), cos(a)] ] )
pos = vector(0,5)*unit(cm)
theta = 30*unit(deg)
arrow from 0,0 to rotate(theta)*pos with linewidth 3
```

In addition to matrix multiplication, other arithmetic operations are available via the methods of matrix objects. Their methods diagonal() and symmetric() return true or false as appropriate. Their size() method returns the vector size of the matrix (rows, columns). Their det() method returns the determinate of the matrix and their transpose() method returns the matrix transpose.

Among more complex operations, inv() returns the inverse of a matrix, eigen­values() returns a vector of the matrix’s eigen­values, and eigen­vectors() returns a list of the matrix’s corresponding eigen­vectors.