How does this compare with R of the qr decomposition? spencer graves

John Fox wrote:

Dear Amin,

I have a function (created just for demonstration, and reproduced below) for
finding the row-echelon form of a matrix. I'm sure that many list members
could produce something that's better numerically, but this should be OK at
least for toy problems.

John

--------- snip -------------

rowEchelonForm <- function(X, tol=.Machine$double.eps){
if ((!is.matrix(X)) || (!is.numeric(X))) stop("argument must be a
numeric matrix")
Z <- X
for (i in 1:min(dim(X))){
if (i > 1) Z[i-1,] <- 0
which <- which.max(abs(Z[,i])) # find maximum pivot in current
column at or below current row
pivot <- X[which, i]
if (abs(pivot) <= tol) next # check for 0 pivot
if (which > i) X[c(i,which),] <- X[c(which,i),] # exchange rows
X[i,] <- X[i,]/pivot # pivot
row <- X[i,] X <- X - outer(X[,i], row) # sweep
X[i,] <- row # restore current row
}
n <- nrow(X)
for (i in 1:n) if (max(abs(X[i,])) <= tol) X[c(i,n),] <- X[c(n,i),] #
0 rows to bottom
X
}




-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Aimin Yan
Sent: Wednesday, March 03, 2004 2:42 PM
To: [EMAIL PROTECTED]
Subject: [R] (no subject)


how to produce a  Row Reduced Echelon Form for a matrix in R?
Aimin Yan

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to