x = linsolve(A,b [,method]);
This function solves the equation
A*x = b;
Where A is a square matrix of arbitrary size n and x and b are vectors of size n.
Returns the inverse of square non-singular matrix A.
The last argument is a string that specifies the desired method to use.
method |
description |
lu |
LU decomposition (default method) |
qr |
QR factorization |
cholesky |
Cholesky factorization |
gmres |
Generalized Minimum Residual |
The gmres method allows further steering of the method by specifying method parameters:
method parameter |
description |
||||||||
tol |
Set the desired tolerance to use |
||||||||
maxiter |
Set the maximum number of iterations to use |
||||||||
ortho |
Set the method of Gramm-Schmidt orthogonalization:
|
The lu, qr and gmres methods allow a non-square matrix A to be entered yielding a pseudoinverse.
A = [1,2;0,1+ramp(1)];
b = [1;5];
x = linsolve(A,b);
x2 = linsolve (A, b, 'qr');
x3 = linsolve (A, b, 'gmres tol=1e-8 ortho=4');
A must be a non-singular square matrix.
The following equations
A*x = b;
x = inverse(A)*b;
x = (A^-1)*b;
all lead in the calculation of the inverse of A and will give the same result as
x = linsolve(A,b);
For the inverse calculation, Cramers rule is used. This is a method which is fast for small matrix sizes. The linsolve function with the gmres method is superior to Cramers rule for larger matrix sizes.