From octave-sources-request at bevo dot che dot wisc dot edu Thu Dec 6 11:30:51 2001 Subject: Echelon form m-files From: Jason Karcz To: octave-sources at bevo dot che dot wisc dot edu Date: Thu, 6 Dec 2001 11:29:53 -0600 --0-1408457445-1007553794=:30943 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Attached are two m-files that can be put in the /usr/share/octave/x.x.x/m/linear-algebra/ directory to add the functionality of row echelon and reduced row echelon form. These are an incredibly large part of linear algebra, and these files have been tested on matricies large and small (including empty). They work. Thanks for looking at them! Jason Karcz __________________________________________________ Do You Yahoo!? Buy the perfect holiday gifts at Yahoo! Shopping. http://shopping.yahoo.com --0-1408457445-1007553794=:30943 Content-Type: text/plain; name="rref.m" Content-Description: rref.m Content-Disposition: inline; filename="rref.m" ## Copyright (C) 2001 Jason E. Karcz ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this file. If not, write to the Free Software Foundation, ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## -*- texinfo -*- ## at deftypefn {Function File} {} rref (@var{x}) ## Computes the reduced row echelon form of a matrix. ## at end deftypefn ## Author: jek function z = rref (x) if (nargin != 1) usage ("rref (x)"); endif x = ref (x); [nr, nc] = size (x); pivr = 1; for i = 1:nc if (pivr <= nr) if (x(pivr,i) != 0) x(pivr,:) = x(pivr,:) / x(pivr,i); if (norm (x(1:pivr-1,i)) != 0 && pivr != 1) tmp = pivr - 1; while (tmp != 0) x(tmp,:) = x(tmp,:) - x(tmp,i) * x(pivr,:); tmp = tmp - 1; endwhile endif pivr = pivr + 1; endif endif endfor z = x; endfunction --0-1408457445-1007553794=:30943 Content-Type: text/plain; name="ref.m" Content-Description: ref.m Content-Disposition: inline; filename="ref.m" ## Copyright (C) 2001 Jason E. Karcz ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this file. If not, write to the Free Software Foundation, ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## -*- texinfo -*- ## at deftypefn {Function File} {} ref (@var{x}) ## Computes the row echelon form of a matrix. ## at end deftypefn ## Author: jek function z = ref (x) if (nargin != 1) usage ("ref (x)"); endif [nr, nc] = size (x); pivr = 1; for i = 1:nc if (norm (x(pivr:nr,i)) != 0 && pivr < nr) if (x(pivr,i) == 0) tmp = pivr+1; while (x(pivr,i) == 0) if (x(tmp,i) != 0) tmpv = x(tmp,:); x(tmp,:) = x(pivr,:); x(pivr,:) = tmpv; endif tmp = tmp + 1; endwhile endif for j = pivr+1:nr x(j,:) = x(j,:) - (x(j,i) / x(pivr,i)) * x(pivr,:); endfor pivr = pivr + 1; endif endfor z = x; endfunction --0-1408457445-1007553794=:30943--