**
****
Mathematics 307
**

**
**

**
Vector calculator routines in calc.inc
**

**
**

Vector addition, subtraction, scaling

Dot product, length

Cross product

Matrix addition, subtraction, scaling

Matrix multiplication,
matrix applied to a vector

Matrix transposition

Solving systems

Row operations

Matrix inverses

2D and 3D rotation matrices

Determinants

##
The data types

Vectors are arrays
`[ number number number ... ]`

like

`[ 2 3 4 ]`

Matrices are arrays of rows

`[
vector vector vector ...
]`

like

`
[`

[ 1 0 0 ]

[ 0 1 0 ]

[ 0 0 1 ]

]

**
**

** The instructions
**

In each case I have tried to show how the stack should look
before and after an operation. Occasionally I include some further
comments.

##
Utilities

**/print
**

displays the top of the stack without destroying it

## Vector algebra

**
/vectoradd
**

x y
**
vectoradd
**

x+y

where x and y are vectors.

**
/vectorsub
**

x y **vectorsub**

x-y

where x and y are vectors.

**
/vectorscale
**

x c **vectorscale**

cx

##
The dot product

**
/dotproduct
**

x y **dotproduct**

x.y

where x and y are vectors.

**
/radius
**

v **radius**

length of vector v

**
/normalize
**

v **normalize**

v/|v|

##
The cross product

**
/crossprod
****
**

u v **crossprod**

u x v

where u and v are 3D vectors

##
Matrix algebra

**
/matrixadd
**

x y **matrixadd**

x+y

**
/matrixsub
**

x y **matrixsub**

x - y

**
/matrixscale
**

x c
**
matrixscale
**

cx

where x is a matrix, c a scalar.

**
/transpose
**

x **transpose**

transpose of x

**
/matrixmul
**

x y **matrixmul**

xy

**
/matrixvector
**

m v **matrixvector**

mv

##
Row operations

where m is a matrix, v a vector.

**
/elementswap
**

m i **elementswap**

swaps items i and j of array m

**
/rowscale
**

m i c **rowscale**

replaces row m[i] of m
by cm[i]

**
/rowsubscale
**

m i j c **rowsubscale**

replaces row m[j] of m
by m[j] - cm[i]

##
Rotations

**
/identity
**

n **identity**

n x n identity matrix

**
/tworotation
**

**tworotation**

2 x 2 matrix representing rotation by x

**
/threerotation
**

axis angle v **threerotation**

v rotated through (scalar) angle around (vector) axis

##
Solving systems

**
/gauss
**

x **gauss**

w l u

replaces matrix x by its three matrix factors
in WLU decomposition.

**
/triangular-solve
**

u y
**triangular-solve
**

x

where ux = y

##
Determinants

**
/twodet
**

a **twodet**

det(a)

where a is a 2 x 2 matrix

**
/threedet
**

a **threedet**

det(a)

where a is a 3 x 3 matrix

##
Inverses

**
/twoinverse
**

a **twoinverse**

matrix inverse of a

where a is a 2 x 2 matrix

**
/threeinverse
**

a **threeinverse**

matrix inverse of a

where a is a 3 x 3 matrix