DADiSP Worksheet Functions > Function Categories > Matrix Math and Special Matrices > ^ (Matrix Solve)

 

\^ (Matrix Solve)

Purpose:

Solves for a matrix.

Syntax:

A \^ b

A

-

A non-singular, usually square matrix.

b

-

A matrix

Returns:

A matrix that produces b when multiplied by A.

Example:

W1: {{1, 4, 7},

     {2, 5, 8}, 

     {3, 6, 0}} 

 

W2: {1,

     2, 

     3} 

 

W3: W1 *^ W2

 

W4: W1 \^ W3

 

 

W3 and W4 contain the following matrices:

 

W3 == {30,

       36,

       15}

 

W4 == {1,

       2,

       3}

 

 

Specifically, W4 solves the following system of equations:

 

x  + 4y + 7z = 30 

2x + 5y + 8z = 36

3x + 6y      = 15

 

x == 1

y == 2

z == 3

Example:

Consider the following over-determined system of equations:

 

x  + 4y + 7z = 30 

2x + 5y + 8z = 36

3x + 6y      = 15

x  + 2y + z  = 2 

 

A = {{1, 4, 7},

     {2, 5, 8}, 

     {3, 6, 0}, 

     {1, 2, 1}} 

 

x = {30,

     36, 

     15, 

      2} 

 

b = A \^ x;

 

b == {-1.8,

       3.2, 

       2.8} 

 

y = A *^ b;

 

y == {30.6,

      34.8, 

      13.8, 

       7.4} 

 

norm(x-y) == 5.6921

 

The \^ operator finds a solution y that minimizes the mean squared error. See LINFIT to fit an arbitrary set of basis functions to a series using the method of least squares.

Remarks:

If A, b, and x are matrices, such that A *^ x = b, then A \^ b returns the matrix x.

 

A \^ b is equivalent to mdiv(A, b).

 

For A \^ b, where A is square, the system is solved using LU decomposition. This is usually numerically more stable than directly calculating the inverse matrix, i.e.

 

x = inv(A) *^ b.

 

If matrix A is not square, the system is considered a least squares problem and is solved by QR decomposition. The resulting matrix is the best solution in the least squares sense.

 

For scalars, a \^ b == a \ b == b * (1/a) == b / a.  For example:

 

10 \^ 2 == 10 \ 2 == 2 * (1/10) == 0.2

 

See DADiSP/MatrixXL to significantly optimize \^.

See Also:

*^ (Matrix Multiply)

/^ (Matrix Right Division)

DADiSP/MatrixXL

INVERSE

LINFIT

LU

MDIV

MMULT

QR

SVDDIV