How Does mldivide Work for Full, Square, Full Rank, Triangular Matrix?
Afficher commentaires plus anciens
How does mldivide work when the input matrix A is full, square, full rank, and triangular? The doc page just say it uses a triangular solver, and I'd like more insight into what that triangular solver is.
An iterative approach can be used, e.g., for a lower triangular A
A = [1 0 0;2 3 0;4 5 6];
b = [1; 2; 3];
% A*x = b
% solve for x(i) iteratively, could be easily done with a for loop
x(1) = b(1)/A(1,1);
x(2) = (b(2) - A(2,1)*x(1)) / A(2,2);
x(3) = (b(3) - A(3,1)*x(1) - A(3,2)*x(2)) / A(3,3);
A*x(:) - b
Does mldivide use a solver that's more efficient and/or more numerically robust?
13 commentaires
Bruno Luong
le 9 Mar 2024
I'm not aware of any drawback of the standard forward/backward substitution algorithm, and any better method.
John D'Errico
le 9 Mar 2024
Why should there be something more numerically robust? Whatever that means here. Just because you want it, this is not suffcient for something to exist. If you are forced to divide by zero, or some very small number, nothing in mathemagics will prevent that divide.
As for the iterative approach you write, that is great for a 3x3 matrix. For larger matrices, you will still be wanting to use linear algebraic operations to perform the computations, thus using the BLAS for efficiency.
Essentially, the code is doing what you wrote, but by use of the BLAS.
Steven Lord
le 10 Mar 2024
The doc page just say it uses a triangular solver, and I'd like more insight into what that triangular solver is.
Might I ask how you're hoping to use that information if it were available? How would your code be different if we told you we used approach X instead of approach Y?
I tend to discourage users from tightly coupling their code to the implementation the release they're using has, as it may mean that when or if we introduce approach Z that is generally "better" their code (tied to approaches X or Y) may not be able to take advantage of that improvement. Sure, some coupling is unavoidable or perhaps even good, but in this case I'd say the coupling is "Use backslash instead of trying to build your own solver."
Paul
le 10 Mar 2024
Bruno Luong
le 10 Mar 2024
@Steven Lord Sometime user needs a precise reference of the algorithm to analyze the the complexity, the performance, the memory required, etc... within a context of watever he and she is developping; especially if it is under scientific review.
Bruno Luong
le 10 Mar 2024
Modifié(e) : Bruno Luong
le 10 Mar 2024
This is more related to how MATLAB compute the rank and disable the projection of the solution into what it considers to the kernel of the system.
In is sense the question is interesting for triangular system since I actually don't know how it estimates the rank.
For the non-triangular full matrix it performs QR decomposition with columns permutation, so the diagonal is decreses in absolute and it cut with the criteria I have asked in another recent post about rank revealing.
If the matrix is already triangular, actually I don't know how the rank and the kernel is actually estimated, since no QR would be performed on top of the triangular matrix, I believe the rank estimation must be performed before the dtrsv (or whatever the equivalent blas function MATLAB uses.
Look for a piece of algorithm won't allow to answer your question IMO.
Paul
le 10 Mar 2024
Bruno Luong
le 10 Mar 2024
Modifié(e) : Bruno Luong
le 10 Mar 2024
I think the test of the matrix (triangular) form does not have tolerance > 0 (such as MATLAB test for symmetric or hermitian). However the rank testing must have ome sort of tolerance.
I have some doubt that MATLAB uses for strict mathematical criteria of full rank for practical numerical rank (for triangular matrix), that would be dangeruous. But this is just my assumption.
Bruno Luong
le 11 Mar 2024
Modifié(e) : Bruno Luong
le 11 Mar 2024
This code shows that MATLAB (R2023B) rank checking are not identical for triangular and not triangular matrix
small = eps(1);
T=[small 0;
1 1];
b = [1;0];
Tf = fliplr(T); % not a upper or lower triagular matrix
% QR method
x1=Tf\b % trigger warning
x1=flipud(x1) % restore the order due to matrix column swap
% back substitution (?)
x2=T\b % no rank warning for lower triangular matrix
% results however matche
x1-x2
Bruno Luong
le 12 Mar 2024
Modifié(e) : Bruno Luong
le 12 Mar 2024
My guess is that the warning during solving x=A\b is not alway triggered based on matrix conditioning number or matrix norm. Those are not cheap to compute.
Rather it's based first on eventual intermediate quantity computed while the linear solver algorithm does the work: smallest and largest diagonal elements of A if A is triangular form, and diagonal of R if QR decomposition is used (generic full matrix).
This code seems to indicate that
- substitution is used directly on T (small is compared to 1 for singularity detection) and
- QR is used on Tf (small is compared to norm([1; 1]) = sqrt(2) for singularity detection)
Christine Tobler
le 13 Mar 2024
Yes, rcond is not computed in x = A\b if A is triangular. This is because computing the approximate rcond value would be several times more expensive than solving the linear system itself. Instead, a heuristic based on the diagonal values of A is used.
Réponses (0)
Catégories
En savoir plus sur Linear Algebra dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!