next up previous contents
Next: Vectorized functions and operators; Up: Arithmetic operations on matrices Previous: Standard operations

Solving matrix equations using matrix division

If A is a square, nonsingular matrix, then the solution of the equation Ax=b is tex2html_wrap_inline681 . Matlab implements this operation with the backslash operator:

>> A = rand(3,3)
A =
    0.2190    0.6793    0.5194
    0.0470    0.9347    0.8310
    0.6789    0.3835    0.0346
>> b = rand(3,1)
b =
>> x = A\b
x =
>> A*x-b
ans =
   1.0e-13 *
(Notice the use of the built-in function rand, which creates a matrix with entries from a uniform distribution on the interval (0,1). See help rand for more details.) Thus A\b is (mathematically) equivalent to multiplying b on the left by tex2html_wrap_inline687 (however, Matlab does not compute the inverse matrix; instead it solves the linear system directly). When used with a nonsquare matrix, the backslash operator solves the appropriate system in the least-squares sense; see help slash for details. Of course, as with the other arithmetic operators, the matrices must be compatible in size. The division operator is not defined for n-dimensional arrays with n>2.

Mark S. Gockenbach
Wed Sep 8 10:44:13 EDT 1999