[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Matlab rref equivalent?
From: |
Dirk Laurie |
Subject: |
Re: Matlab rref equivalent? |
Date: |
Tue, 16 May 2000 08:46:52 +0200 (SAST) |
=?ISO-8859-1?Q?St=E9fan_van_der_Walt?= skryf:
>
> Hi,
>
> How do one reduce a matrix to row echelon or reduced row echelon form in
> Octave? (rref func in matlab for example)
>
> Regards,
> Stefan van der Walt
>
function [R,k]=rref(A,tol)
% reduced row echelon form
[m,n]=size(A); p=max(m,n);
if nargin<2, tol=p*eps*norm(A,inf); end
% pad matrix with zeros to make it square
if m~=n, A(p,p)=0; end
[L,U,P]=lu(A);
k=find(abs(diag(U))>tol);
R=U(k,k)\U(k,:);
% remove added columns if any, add correct number of zero rows
if n<p, R(:,n+1:p)=[]; end
if length(k)<m, R(m,n)=0; end
endfunction
Dirk
-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.che.wisc.edu/octave/octave.html
How to fund new projects: http://www.che.wisc.edu/octave/funding.html
Subscription information: http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------