Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Change language to: Français - Português - 日本語 - Русский
Scilab Help >> Scilab > Scilab keywords > backslash

backslash

(\) left matrix division: Exact or least square solution

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 conditioned), the LU factorization with row pivoting is used. If not (i.e. if A is poorly conditioned), 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

"/modules/umfpack/demos/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());

• slash — (/) right divisions. System's feed back. Comments
• lsq — linear least square solution of A*X=B with minimal norm(X)
• inv — matrix inverse
• pinv — pseudoinverse
• linsolve — linear equation solver
• umfpack — solve sparse linear system
• datafit — Non linear (constrained) parametric fit of measured (weighted) data
• kron .\. — Kronecker left and right divisions

History

 Version Description 5.5.0 The threshold level which switches between Gaussian Elimination with row pivoting and linear least squares when computing A\B is decreased from sqrt(eps) to eps.