Matrices in R

This section provides details on the construction and manipulation of these objects, including matrix facilities that are different from typical element-wise operations.

Matrices

Linear equations and inversion

Solving linear equations is the inverse of matrix multiplication. When after

> b <- A %*% x

only A and b are given, the vector x is the solution of that linear equation system. In R,

> solve(A,b)

solves the system, returning x (up to some accuracy loss). Note that in linear algebra, formally x = A^{-1} %*% b where A^{-1} denotes the inverse of A, which can be computed by

solve(A)

but rarely is needed. Numerically, it is both inefficient and potentially unstable to compute x <- solve(A) %*% b instead of solve(A,b).

The quadratic form  x %*% A^{-1} %*% x   which is used in multivariate computations, should be computed by something like17 x %*% solve(A,x), rather than computing the inverse of A.