0
$\begingroup$

How can I determine a matrix $R$ in matlab such that, given a known matrix of coefficients $A$ gives me back its row reduced echelon form? Obviously I need an algorithm/function that works also with matrices that are not fully ranked.

$$ RA=\text{rref}A $$ I don't know how to handle this... please can anybody help me? Thanks a lot! :)

$\endgroup$
  • $\begingroup$ I suppose that you can find the echelon form and then solve a series of systems of equations. $\endgroup$ – nicoguaro Nov 8 '16 at 19:05
  • 1
    $\begingroup$ The row reduced echelon form is computed by Gauss elimination, so an adapted LU factorization will do the trick (e.g., mathworks.com/matlabcentral/fileexchange/…). There are other rank revealing factorizations that might be more stable; see, e.g., math.sjsu.edu/~foster/rankrevealingcode.html. $\endgroup$ – Christian Clason Nov 10 '16 at 8:50
  • $\begingroup$ rref is a blackboard method as in Gauss elimination. Numerically, in general they don't work as advertised for all cases. What you have in mind is usually done via LU or RRQR decompositions $\endgroup$ – percusse Nov 12 '16 at 9:53
3
$\begingroup$

Try this! Example here has rank 2 for a 3x3 matrix.

A = [1 1 1; 2 2 2; 5 7 6];
rrefA = rref(A);

disp(rrefA) % rref of A

C=[A eye(size(A))];

rrefC = rref(C);

R=rrefC(:,4:6); 
disp(R*A) % should get rref of A
disp(R)
| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Yeah, I have solved everything with the same approach! $\endgroup$ – james42 Nov 10 '16 at 16:29
  • 1
    $\begingroup$ This will not work for non-square $A$, when the number of rows is greater than the number of columns. $\endgroup$ – Stefano M Nov 11 '16 at 6:53
0
$\begingroup$

I still cannot understand what this $R$ is good for, but in matlab you can simply (ab)use the slash operator:

>> [rrefA, jb] = rref(A);
>> R = rrefA(:,jb)/A(:,jb);

Here an example, showing that this method works also for non square matrices:

>> A = randn(10,3)*randn(3,4);
>> rank(A)

ans =

     3

>> size(A)

ans =

    10     4

>> [rrefA, jb] = rref(A);
>> R = rrefA(:,jb)/A(:,jb);
>> rank(R)

ans =

     3

>> norm(R*A-rrefA)/norm(A)

ans =

   1.7351e-15

Please note that this answer is just code golf: reduced row echelon form is not the most stable rank revealing factorisation, as noted above by Christian Clason.

| cite | improve this answer | |
$\endgroup$
-2
$\begingroup$

You can solve the equation for $R$, then use the resulting term: $$R = rref(A)*A^{-1}$$

| cite | improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ This doesn't work when $A$ is not fully ranked $\endgroup$ – james42 Nov 9 '16 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.