# Vocabulary/percentdot

>>
<< ` `
Down to: Dyad ` `
Back to: Vocabulary
Thru to: Dictionary

`%. y`Matrix Inverse

Rank 2 *-- operates on tables of y --*
WHY IS THIS IMPORTANT?

- The
*inverse matrix*of square matrix`y`, denoted*y^-1^* - If
`y`is not square,`%. y`is the*left inverse*of`y`, defined below.

]P=: 0 0 1 , 1 0 0 ,: 0 1 0 NB. permutation matrix 0 0 1 1 0 0 0 1 0 %. P NB. The inverse of P is also a permutation matrix 0 1 0 0 0 1 1 0 0

### Common Uses

1. To reverse the effect of a linear transformation.

2. Given a rotation matrix, to form the matrix that rotates in the opposite direction.

sin=: 1&o. cos=: 2&o. angle=: (o.2) % 12 NB. 30 degrees, in radians ] R=: 2 2$ (cos,-@sin,sin,cos) angle NB. R: rotate by (angle) 0.866025 _0.5 0.5 0.866025 ] S=: 2 2$ (cos,-@sin,sin,cos) -angle NB. S: rotate by (-angle) 0.866025 0.5 _0.5 0.866025 S -: %.R NB. S is the inverse of R 1 R -: %.S NB. R is the inverse of S 1

3. If `y` is a vector, `%. y` is a vector in the same direction as `y` but with reciprocal length.

### Related Primitives

Matrix Product (x `+/ . *` y)

### More Information

1. If the columns of `y` are dependent, `domain error` is signaled.

2. If `y` is not square, `%. y` is (in standard mathematical notation) ((*y***y*)^-1^*y**)
where *y** is the **adjoint** of *y*, that is the *complex conjugate* of the transpose of *y*
(for real matrices, this is the same as the transpose of *y*).

With this definition it is always true that `(%. y) +/ . * y` is an identity matrix.

### Details

1. If `y` is an atom or a list, it is reshaped to a 1-column table, and the result is reshaped to the same shape as `y`.

1. If `y` is a table, the shape of `%. y` is the reverse of the shape of `y`; put another way, `%. y` has the same shape as `|: y`.

`x %. y`Matrix Divide

Rank _ 2 *-- operates on the entirety of x and tables of y --*
WHY IS THIS IMPORTANT?

`x %. y` is `(%. y) mux x` where `mux` denotes matrix multiplication.

- When
`y`is square, the result R of`x %. y`solves the matrix equation`y mux R -: x`.

`-:` corresponds to `=` in standard mathematical notation.

- When
`y`is not square, the result`R`comes as close as possible to solving the equation, in the minimum-squared-error sense.

sin=: 1&o. cos=: 2&o. mux=: +/ . * NB. matrix-multiply angle=: (o.2) % 12 NB. 30 degrees ]R=: 2 2$ (cos,-@sin,sin,cos) angle NB. rotate by (angle=30 deg) 0.866025 _0.5 0.5 0.866025 angle=: (o.2) % 24 NB. 15 degrees ]Q=: 2 2$ (cos,-@sin,sin,cos) angle NB. rotate by (angle=15 deg) 0.965926 _0.258819 0.258819 0.965926 angle=: (o.2) % 8 NB. 45 degrees ]P=: 2 2$ (cos,-@sin,sin,cos) angle NB. rotate by (angle=45 deg) 0.707107 _0.707107 0.707107 0.707107 Q mux R NB. Rotate successively by 15 deg, then by 30 deg (total=45 deg) 0.707107 _0.707107 0.707107 0.707107 P -: Q mux R NB. Rotation by 45 degrees is the same even if done in 2 steps 1 (P %. R) -: Q NB. Matrix-divide both sides of the equation by R 1

### Common Uses

1. To solve a system of linear equations.

2. To calculate a linear regression:

indep =. 1 2 3 5 6 NB. independent variable dep =. 3 4 5 8 9 NB. dependent variable dep %. (indep ,. 1) NB. calculate line of best fit 1.24419 1.56977

The best fit is `dep = 1.57 + 1.24 * indep`.

3. To calculate the current flows in a given electrical circuit network using Kirchhoff's Laws.

### Related Primitives

Matrix Product (`x +/ . * y`)

### More Information

1. The columns of `y` must be independent, or `domain error` is signaled.

1. In standard mathematical notation, the result is ((*y***y*)^-1^*y***x*) where *y** is the **adjoint** of *y*,
i.e. the complex conjugate of the transpose of *y* (for real matrices, this is the same as the transpose of *y*). If `y` is square this simplifies to (*y*^-1^*x*)

1. If `y` is an atom or a list, it is reshaped to a 1-column table.

1. If `x` is a list, it is reshaped to a 1-column table.

1. If `x` is an atom, it is repeated as needed to make a 1-column table that conforms to `%. y`.
1. The shape of `x %. y` is `y ,&}.&$ x`, which is rather subtle. If `y` and `x` are both tables, the result has many rows as `y` has columns, and the same number of columns as `x`.
But if `x` or `y` is an atom or list, the corresponding axis of the result (which would be of length 1) is omitted. Thus:

$ (,. 1 2 3) %. (,. 6 7 9) NB. 3x1 table %, 3x1 table: 1x1 result 1 1 $ (1 2 3) %. (,. 6 7 9) NB. list %. 3x1 table: result is 1-atom list 1 $ (1 2 3) %. (6 7 9) NB. list %. list: scalar result.