Contents Previous Next Subchapters

Linear Equations and Least Squares
Syntax left value \ right value
See Also matrix multiplication , element-by-element division , inv

Description
Solves for the matrix that yields the right value when multiplied by the left value, where the values are real, double-precision, or complex. If the left value is not a square matrix, the result is the least-squares solution.

Tutorial

Scalars
If the left value is a scalar, the result is the element-by-element division of the left value into the right value. If you enter
     print 5 \ [ 2.0 , 3.0 ] 
O-Matrix will respond
     [ 0.4 , 0.6 ]

Dividing by Square Matrices
You can solve the linear equation A x = b using the matrix divide operator (\). For example, to solve the system of equations
     2 x + 3 y = 4
     3 x + 5 y = 2
which can be represented as
     / 2  3 \ / x \    / 4 \
     |      | |   |  = |   |
     \ 3  5 / \ y /    \ 2 /
enter
     A = {[2., 3.], [3., 5.]}
     b = {4., 2.}
     A \ b
O-Matrix will then respond
     {
     14
     -8
     }

Solving Linear Least Squares Equations
You can also solve linear least squares equations using the matrix divide operator. To find the least squares solution of the equations
     4 x = 2
     3 x = 2
enter
     A = {4., 3.}
     b = {2., 2.}
     A \ b
to which O-Matrix will respond
     0.56
This is the solution to the problem
                       2             2
     minimize (4 x - 2)  +  (3 x - 2)  with respect to x

Algorithm
If the left value is a square matrix an LU factorization is used to solve the linear equations. Otherwise, a QR factorization is used to solve the linear least square problem.

Reference
If the value types do not agree, O-Matrix will coerce the values as detailed in the coercion table (unless the result would be an integer, in which case the result is double-precision).

If the left value is not a scalar, the row dimensions of the left and right values must be equal. In this case, the row dimension of the result is equal to the column dimension of the left value. The column dimension of the result is equal to the column dimension of the right value.