# backslash

(\) left matrix division.

## Calling Sequence

    x=A\B

## Description

Backslash is the left matrix division: `x=A\B` is a solution to `A*x=B`.

If `A` is square and non-singular `x=A\B` is equivalent to `x=inv(A)*B` in exact arithmetic, but the computations are more accurate and cheaper in floating point arithmetic. Hence, to compute the solution of the linear system of equations `A*x=B`, the backslash operator should be used, and the `inv` function should be avoided.

In the case where A is square, the solution `x` can be computed either from LU factorization or from a linear least squares solver. If the condition number of A is smaller than 1/(10*%eps) (i.e. if A is well conditionned), the LU factorization with row pivoting is used. If not (i.e. if A is poorly conditionned), then X is the minimum-norm solution which minimizes `||A*X-B||` using a complete orthogonal factorization of A (i.e. X is the solution of a linear least squares problem).

If `A` is not square, `x` is a least square solution, i.e. `norm(A*x-B)` is minimal (Euclidean norm). If `A` is full column rank, the least square solution, `x=A\B`, is uniquely defined (there is a unique `x` which minimizes `norm(A*x-B)`). If `A` is not full column rank, then the least square solution is not unique, and `x=A\B`, in general, is not the solution with minimum norm (the minimum norm solution is `x=pinv(A)*B`).

`A.\B` is the matrix with `(i,j)` entry `A(i,j)\B(i,j)`. If `A` (or `B`) is a scalar `A.\B` is equivalent to `A*ones(B).\B` (or `A.\(B*ones(A))`.

`A\.B` is an operator with no predefined meaning. It may be used to define a new operator (see overloading) with the same precedence as `*` or `/`.

## Examples

    A=[
       9.   -36.    30.
      -36.   192.  -180.
       30.  -180.   180.
    ];
    b=[
       3.
      -24.
       30.
    ];
    x=A\b
    A*x-b // close to zero

    A=rand(3,2);
    b=[1;1;1];
    x=A\b;
    y=pinv(A)*b;
    x-y
    A=rand(2,3);b=[1;1];
    x=A\b;
    y=pinv(A)*b;
    x-y, A*x-b, A*y-b

    // if rank is deficient
    A=rand(3,1)*rand(1,2);
    b=[1;1;1];
    x=A\b;
    y=pinv(A)*b;
    A*x-b, A*y-b
    A=rand(2,1)*rand(1,3);
    b=[1;1];
    x=A\b;
    y=pinv(A)*b;
    A*x-b, A*y-b

    // A benchmark of several linear solvers

    [A,descr,ref,mtype] = ReadHBSparse(SCI+..
       "/modules/umfpack/examples/bcsstk24.rsa");

    b = zeros(size(A,1),1);

    tic();
    res = umfpack(A,'\',b);
    mprintf('\nTime with umfpack: %.3f\n',toc());

    tic();
    res = linsolve(A,b);
    mprintf('\ntime with linsolve: %.3f\n',toc());

    tic();
    res = A\b;
    mprintf('\ntime with backslash: %.3f\n',toc());

## See Also

- slash
- inv
- pinv
- percent
- ieee
- linsolve
- umfpack

## History

5.4.1
The threshold level for conditioning in blackslash increased.