3

I found that rref in Matlab does the gaussian elimination with patial pivoting Let A for example be a 5x9 matrix:

0.4898    0.2760    0.4984    0.7513    0.9593    0.8407    0.3500    0.3517    0.2858
0.4456    0.6797    0.9597    0.2551    0.5472    0.2543    0.1966    0.8308    0.7572
0.6463    0.6551    0.3404    0.5060    0.1386    0.8143    0.2511    0.5853    0.7537
0.7094    0.1626    0.5853    0.6991    0.1493    0.2435    0.6160    0.5497    0.3804
0.7547    0.1190    0.2238    0.8909    0.2575    0.9293    0.4733    0.9172    0.5678

rref(A) gives:

1.0000         0         0         0         0   10.9716   -6.2494   33.3062   16.0275
     0    1.0000         0         0         0   -2.2910    1.6003   -9.5889   -3.9001
     0         0    1.0000         0         0   -3.3952    1.8012   -6.8843   -3.4078
     0         0         0    1.0000         0   -8.3071    5.8617  -27.3981  -13.0805
     0         0         0         0    1.0000    4.2036   -2.4313   11.1545    5.2517

How to obtain the same result as rref by performing LU factorization of A? I found that LU factorization does gauss elimination with partial pivoting as well. How to replace in a code rref with LU? What are the steps to do after [L,U]=lu(A) to obtain the same result as rref(A) of the above example.

Didon
  • 383
  • 2
  • 4
  • 13
  • 1
    You are correct in that LU does perform partial pivoting, but that is used to obtain `U`, which is an upper triangular matrix. This is in reduced echelon form, but only forms **half** of the picture. `U` itself doesn't represent `A`. `L` and `U` give upper and lower triangular matrices where when you multiply them, you get `A`. With this, I don't see how you can use `LU` to obtain the RREF. Instead of answering your question, I'm going to provide you with another. Why do you need to use LU to get to RREF? What are its implications in doing so? Do you **have** to do it this way? – rayryeng Feb 24 '15 at 18:24
  • I'm trying to convert a Matlab code to C and perform algebra routines by interfacing the C code with the Intel MKL math library. In this library, I couldn't find a function to perform rref and i found instead several functions performing LU, QR, SVD ... I thought to replace rref in the matlab code first and then finding the appropriate function in the Intel MKL library – Didon Feb 24 '15 at 18:38
  • OK, here's another question for you. Why do you need to use RREF? RREF is not used as often as you think. If you want to use RREF to solve a linear system, you can use anything else (LU even) to help you do that. If you want to find the rank, you can use the SVD for that and count the number of singular values. RREF by itself is pretty numerically unstable so other things are used to replace it for the particular application that you want. Because I don't know what application you're writing for, I can't suggest anything. – rayryeng Feb 24 '15 at 18:42
  • I'm working on the conversion of the essential matrix five point algorithm of Henrik Stéwénius (vis.uky.edu/~stewe/FIVEPOINT/) The matlab code is opensource and there exist two versions: the first one employing mldivide and the second employing rref – Didon Feb 24 '15 at 19:13
  • OK, I see why you need RREF. I'm pretty sure you can't use any of the other algorithms (LU, QR, SVD, etc.) to reshape the matrix into what you want because RREF simply mutates the matrix so that it is a different representation, while the other algorithms **decompose** the matrix into a product of matrices. You may have to write your own code for RREF. Check out Rosetta Code for already coded algorithms in a variety of languages: http://rosettacode.org/wiki/Reduced_row_echelon_form – rayryeng Feb 24 '15 at 19:13
  • Thank you for your help. May I ask you about mldivide..it is used as follows: A=A1\A2 where A1 and A2 are 10x10 real matrices..this usually solves the sytem A1*X=A2, can I solve this system using another method like decomposing A1 into LU and then performing the remaining steps? – Didon Feb 24 '15 at 19:24
  • Yes. Decompose `A1 = LU`. Therefore, `LUX = A2`, then let `UX = Z`. As such, we have `LZ = A2`. `L` and `A2` are known, and you can solve for `Z`. `Z` can be found by simple back-substitution. Next, substitute `Z` into `UX = Z` and solve for `X`. `U` and `Z` are known (`Z` from the previous step). You can also solve for `X` by back-substitution. – rayryeng Feb 24 '15 at 19:29
  • Thank you, I will try it and see what it gives – Didon Feb 24 '15 at 19:31
  • The matrix U from an LU factorization is the row echelon form of A. If you want the reduced form, you just need to reduce U. That is, scale each row so the pivots are one and then subtract multiples of rows to cancel values in pivot columns. – Jeremy West Mar 01 '15 at 09:57
  • @Jeremy West alright thank you! – Didon Mar 04 '15 at 15:16

1 Answers1

0

If you assume A (of size n x m) is a compound matrix such as A = (A1 | A2) with A1 a n x n matrix and A2 a n x (m-n) matrix.

If A1 is invertible, then you can write R, the Reduced Row Echelon Form of the matrix A:

R = A1^-1 (A1 | A2) = (Id | A1^-1 A2)

You can thus use a LU decomposition or a direct multi-RHS solver to compute A1^-1 A2.

Johann Bzh
  • 834
  • 3
  • 10
  • 25